UITableView的使用-1

UITableView作为IOS开发最重要的控件,下面就来介绍下如果使用这个控件

(一)、介绍

1. 首先在代码中设置UITableView的数据源

如:self.tableView.dataSource = self;

2. 给数据源控制器实现UITableView的协议

如:@interfaceViewController () <UITableViewDataSource>

@property (strong,nonatomic) IBOutletUITableView *tableView;

@end

3. 实现协议中的3个关键方法

// 告诉tableView每一组有多少行数据

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

// 告诉tableView一共有多少组数据

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

// 告诉tableView每一行显示什么数据

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

4.其他方法

// 返回每一组头部标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {};

// 返回每一组尾部标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {};


注意点

(1).在 cellForRowAtIndexPath 行为中,如果 UITableViewCell 声明的时候用 initWithStyle 方式的话,可以使用子标题功能:

UITableViewCell *cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];

...

cell.detailTextLabel.text = @"...";

(2). - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView; 这个方法可以不实现,默认返回1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值