美文网首页
iOS开发初级篇(-、基础004)

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

作者: feitry | 来源:发表于2018-07-24 15:09 被阅读0次

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

相关文章

网友评论

      本文标题:iOS开发初级篇(-、基础004)

      本文链接:https://www.haomeiwen.com/subject/gizemftx.html