黑马程序员-IOS学习笔记-UITableView1

------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------

一、UITableView

iOS中显示数据列表最常用的一个控件,支持垂直滚动。


二、UITableView 的两种内置样式

1.UITableViewStylePlain 不带分组的。

2.UITableViewStyleGrouped  带有分组的。


三、数据源(dataSource)和代理(delegate)

1.UITableView需要一个数据源(dataSource)来显示数据,UITableView会向数据源查询一共多少行数据以及每一行显示什么数据等。没有设置数据源的UITableView只是一个空壳,凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的数据源。

2.通常都要为UITableView设置代理对象(delegate),以便在UITableView触发一下事件时做出相应的处理,比如选中某一行。凡是遵守了UITableViewDelegate协议的OC对象。都可以是UITableView的代理对象。

3.一般会让控制器充当UITableView的dataSource和delegate


四、UITableViewDataSource协议内部的方法。

@required


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
第section分区一共有多少行


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
创建第section分区第row行的UITableViewCell对象(indexPath包含了section和row)


@optional


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;    一共有多少个分区


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
第section分区的头部标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
第section分区的底部标题


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
某一行是否可以编辑(删除)


- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
某一行是否可以移动来进行重新排序


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
UITableView右边的索引栏的内容


五、UITableViewDelegate协议内部方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
选中了UITableView的某一行


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
某一行的高度


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
第section分区头部的高度


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
第section分区尾部的高度


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
第section分区头部显示的视图


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
第section分区尾部显示的视图


- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
设置每一行的等级缩进(数字越小,等级越高)


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值