項(xiàng)目中需要展現(xiàn)用戶的家庭成員,第一行是用戶自己,下面分別是用戶的家庭成員。成員可被編輯、刪除,但用戶本身只能編輯資料,不可被刪除??梢岳肬ITableViewDelegate中的
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath方法對(duì)不同的cell自定義左滑動(dòng)作。
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定義
[self deleteMember:indexPath];
}];//此處是iOS8.0以后蘋果最新推出的api,UITableViewRowAction,Style是劃出的標(biāo)簽顏色等狀態(tài)的定義,這里也可自行定義
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"編輯" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self deleteMember:(NSIndexPath *)indexPath];
}];
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"編輯" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self editMember:(NSIndexPath *)indexPath];
}
if (indexPath.row>0) {
return @[deleteRoWAction, editRowAction];//最后返回這倆個(gè)RowAction 的數(shù)組
}
else{
return @[editAction];//row=0時(shí)只返回編輯按鈕
}
}