iOS:UITableView 方法 属性 详解

参考:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html <UITableView Class Reference>  + UITableView.h

简介:

--一个@的实例意味着展示和编辑分层列表的信息。一个tableview在一栏中展示了一系列item,它是UIScrollview的子类,允许用户在列表上滑动,但只能是垂直方向。

--tableview有俩种样式,见下图:

==================datasource方法==================

@required
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
// Default is 1 if not implemented
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; //每个section的title
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section; //每个section的footer

// Editing/Moving or Reordering

// 不同的row可以有同的-editing属性。当row的editing属性为NO,则它不可编辑(tableview setEditing改变的时候它没影响);为YES时,可编辑,可以有不同的editingStyle,详见"editingStyleForRowAtIndexPath方法"。Default is YES;
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
// 不同的row是否可以移动。当tableview处于editing状态时:如果某个row返回值为NO,则它的reorder accessory view不会显示,不可移动;如果某个row的返回值为YES的时候,且datasource有实现-tableView:moveRowAtIndexPath:toIndexPath:方法,则显示该row的reorder accessory view 可以移动,否则还是不显示reorder accessory view,不可移动;
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// Index 

//返回list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
// which section corresponds to sectionIndexTitle,当点击某个sectionIndexTitle时候,返回某个section的值,tableview就移动到该section;
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  

// Data manipulation - insert and delete / reorder or moving  support

// 当tableview处于editing状态时,如果row可编辑,则会has the minus or plus button invoked(based on the UITableViewCellEditingStyle for the cell)。当点击minus or plus button的时候,就会调用该方法(如果是minus button,需要点击到随后的delete才会触发方法);
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
// 当tableview处于editing状态,并且row可以canMove,如果拖动某row换行,则调用改方法;
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
@end
================== delegate方法==================

@optional
// Display customization
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

// Variable height support
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

// tableview在每次reload data时都会要所有cell的高度,这非常影响程序性能,使用estimatedHeight methods to quickly calcuate guessed values 去快速加载tableview
// 原理:If
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值