Tableview快速上手(方法注释到位哦)

TableView 是object-c最最最常用的控件了  、来掌握它吧

一)UITableView所在的UIViewController声明两个delegate:UITableViewDelegate和UITableViewDataSource。

二)将UITableView对象的delegate设置成self。

三)根据实际需要实现delegate的具体方法,这里简要介绍一下常用的方法和属性。

1、返回tableview有多少个section

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

2、返回对应的section有多少个元素,也就是每个section对应有多少个cell

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

3、 返回指定的row高度

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

4、返回指定的section的header view的高度

- (CGFloat)tableView:(UITableView *)tableView  heightForHeaderInSection:(NSInteger)section 

5、返回指定的section的footer view的高度

- (CGFloat)tableView:(UITableView *)tableView  heightForFooterInSection:(NSInteger)section

6、  返回指定row的cell,在此函数中用户可以根据自己的需求定义cell的属性和显示风格等(主标题cell.textLabel,副标题cell.detailTextLabel,背景cell.imageView,图标cell.accessoryType等等)

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

7、 返回指定section的header的titile。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

8、  返回指定section header的view

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

9、 用户选中某cell时的回调函数

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

10、 获取某一cell对象

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 

如果想让cell能响应选中事件,但是选中后的颜色不发生改变的话,设置cell.selectionStyle = UITableViewCellSelectionStyleNone。

如果想删除cell之间的分割线,设置  tableview.separatorStyle = UITableViewCellSeparatorStyleNone。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值