iOS中tableview 中不同cell分別自定義左滑選項(xiàng)

項(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í)只返回編輯按鈕
}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容