UITableViewDataSource和UITableViewDelegate内常用的13个方法

@protocol UITableViewDataSource<NSObject>

@required

//设置分组的行数

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


//创建cell,每一个行(row)对应一个cell

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


@optional

//设置分组个数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;


//设置分组头(标题)显示的文字

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


//设置UITableView右边的索引值

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


//设置每一行的编辑状态

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


//按钮点击事件

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


//设置tableView每一行是否允许移动

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


//提交移动之后触发

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




UITableViewDelegate

//设置每行row的高度

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

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

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


//设置当点击删除按钮时,提示的确认文字

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPathNS_AVAILABLE_IOS(3_0){

    return@"确认删除";

}


//移动时只能在本区内移动(设置cell移动的位置)

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值