UITableViewDataSource

UITableViewDataSource
关于UITableView的一些相关的属性和方法,以及一些代理方法的使用.
说到UItableView的一个代理 是:UITableViewDataSource

返回cell的数量
- ( NSInteger ) numberOfSectionsInTableView: ( UITableView * nonnull ) tableView

知道现在的cell是哪一个.即得到当前的cell的标签,然后通过标签来做其他的事情
- (UITableViewCell * nonnull)tableView:(UITableView * nonnull)tableView cellForRowAtIndexPath:(NSIndexPath * nonnull)indexPath

在section里现在的row的序号
- (NSInteger)tableView:(UITableView * nonnull)tableView numberOfRowsInSection:(NSInteger)section

显示右边的导航标题

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView


当点击右边的标题的时候,就可以直接的跳转到指定的title处,不论你点的是什么,直接跳转返回值处

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index


根据section来设置titleHeader

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


根据section来设置titleFooter

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


根据点击的编辑按钮,来执行相应的处理

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

在可以编辑之前必须要把tableView的setEditing设置成YES.

代码如下:

[tableView setEditing:YES];

在代理方法里判断editingStyle来执行相对应的处理.


可以根据indexPath来设置是否可以被编辑

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath


是否可以移动cell,可以根据indexPath来判断

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

但是,要与下面的方法结合使用:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

在移动的时候,要注以的是,数据先行,视图后行.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值