侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Objective-C --- - UITableView 一注册机制简单例子(梳理总结)

2024-05-15 星期三 / 0 评论 / 0 点赞 / 84 阅读 / 2613 字

1.准备 2.简单设置 // 两种类型 一般Plain 不设置默认为Plain // typedef NS_ENUM(NSInteger, UITableViewStyle) { // UI

1.准备

2.简单设置

//    两种类型  一般Plain  不设置默认为Plain

//    typedef NS_ENUM(NSInteger, UITableViewStyle) {

//        UITableViewStylePlain,          // regular table view

//        UITableViewStyleGrouped         // preferences style table view

//    };    

    _tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];

    [self.view addSubview:_tableView];

  //    设置代理和数据来源

    _tableView.delegate = self;

    _tableView.dataSource = self;

    

//    注册方式

//    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellID];

 

3.代理方法实现和复用

 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

//    return 3;//3组

    

    return self.dataList.count;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

//    return 5;//每组5个ROW,可以对section进行判断来分别设置几个ROW

    

    return [self.dataList[section] count];

}

 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

//    设置高度

    return 78.0f;

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];

 

//    复用机制

    if (cell == nil) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];

//    UI可以复用  数据不能  如果是注册这里就不写

 

    }

    

    cell.textLabel.text = self.dataList[indexPath.section][indexPath.row];

 

    return cell;

}

 

广告 广告

评论区