首页 > 其他 > 详细

UITableView创建步骤与常用数据源方法

时间:2016-04-04 19:42:54      阅读:192      评论:0      收藏:0      [点我收藏+]

创建步骤

  • 创建tableView对象
      UITableView *tableView=[[UITableView alloc]init];
      tableView.frame=self.view.bounds;
    
  • 实现协议UITableViewDataSource
  • 设置数据源
      tableView.dataSource=self;
    
  • 实现协议的一些方法
      //返回每一组的条数
      -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
      return 50;
    }
    //返回cell
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
      cell.textLabel.text=[NSString stringWithFormat:@"test%zd",indexPath.row];
      return cell;
    }
    
  • 此时还可以设置代理UITableViewDelegate(可选)

常用数据源方法

  • 设置有多少分组
      -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    
  • 设置每组有多少个cell
      -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    
  • 设置cell数据
      -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    
  • 设置组头标题
      - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
    
  • 设置组尾部标题
      - (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

UITableView创建步骤与常用数据源方法

原文:http://www.cnblogs.com/JavaTWW/p/5352623.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!