首页 > 移动平台 > 详细

iOS ,UITableViewDataSource 和 UITableViewDelegate协议中常用方法

时间:2014-09-09 16:13:59      阅读:254      评论:0      收藏:0      [点我收藏+]

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
{
  1.创建重用标识符
   static NSString *identifier = @"reuse”;

 2.去重用队列中根据标识符取可重用的cell 

  AddressBookCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];     

3.判断是否获取到可重用的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

iOS ,UITableViewDataSource 和 UITableViewDelegate协议中常用方法

原文:http://blog.csdn.net/hakusan/article/details/39155567

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!