iOS开发初级篇(-、基础004)

UITableView
实在没啥好讲的,直接来代码:

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];//初始化对象
    _tableView.dataSource = self;//遵循数据源
    _tableView.delegate = self;//遵循代理
    [self.view addSubview:_tableView];//添加到父视图

}
#pragma mark - UITableViewDataSource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
    }
    cell.textLabel.text = @"textlable";//设置文字
    return cell;
}
@end

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AGI阅读 16,018评论 3 119
  • 国学教育,古已有之,今又重来,复古乎,倒退乎,均不是,“温故而知新也”。社会在发展,时代在进步,但是历史不是...
    2dbd67f8c77a阅读 413评论 0 0
  • 《稻盛哲学学习会》打卡第117天 姓名:严娜 部门:分水碶 组别:待定 【知~学习】 诵读《京瓷哲学》 6 思考人...
    NinaYanWellin阅读 163评论 0 0
  • 2018年1月24日功课 第一部分 忏悔 1、爸爸妈妈,对不起,昨天和今天我都没有好好爱惜身体! 2、爸爸,对不起...
    馨只有你191413阅读 171评论 0 0
  • 茄子是很百搭的食物,烧法百变,各有千秋。 但对烧菜人的手艺要求极高,加油加料,最难拿捏的是“度”。 因此擅长烧茄子...
    蝶舞芙蓉阅读 491评论 0 4