iso UITableViewDataSource 和 UITableViewDeleg协议中常

UITableViewDataSource 协议中常用方法

1.设置右边 索引值

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

2. 设置分组标识

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

3.

设置分组个数

- ( NSInteger )numberOfSectionsInTableView:( UITableView

*)tableView

4. 设置行数

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

5. 创建

cell(使用重用机制,如下例)

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

*)indexPath

{

a.

创建重用标识符

static NSString *identifier = @"reuse”;
b. 去重用队列中根据标识符取可重用的 cell  

AddressBookCell *cell = [tableView dequeueReusableCellWithIdentifier :identifier];     

c. 判断是否获取到可重用的 cell( 最后要空间释放 )    

if (!cell) {     

cell = [[[ AddressBookCell alloc ] initWithStyle : UITableViewCellStyleDefault reuseIdentifier :identifier] autorelease ];   

}

return cell;

}

6. 设置 tableView 的每一行的编辑状态

(YES,可编辑)

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

*)indexPath

{

return YES

}

7.edit 按钮的点击事件 ( 当点击 edit 按钮时触发 )

- ( void )setEditing:( BOOL )editing animated:( BOOL )animated

8. 当提交编辑操作时触发

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

9. 设置 tableView 每一行是否允许移动(YES,可移动)

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

{

return YES

}

10. 提交移动操作之后触发

- ( void )tableView:( UITableView *)tableView moveRowAtIndexPath:( NSIndexPath *)sourceIndexPath toIndexPath:( NSIndexPath *)destinationIndexPath

UITableViewDelegate协议中常用方法

1. 设置行高

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

{

return 55;

}

2. 选中cell时触发

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

3. 设置 tableViewCell 的编辑样式 ( 插入 / 删除 )

- ( UITableViewCellEditingStyle )tableView:( UITableView *)tableView editingStyleForRowAtIndexPath:( NSIndexPath *)indexPath

4. 设置当点击编辑按钮时 上面显示的文字,如显示删除

- ( NSString *)tableView:( UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:( NSIndexPath *)indexPath NS_AVAILABLE_IOS ( 3 _0) {    return @" 删除 " ; }

5. 设置 cell 移动的位置

- ( NSIndexPath *)tableView:( UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:( NSIndexPath *)sourceIndexPath toProposedIndexPath:( NSIndexPath *)proposedDestinationIndexPath



转载于:https://my.oschina.net/xiahuawuyu/blog/539808

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值