亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

UITableViewCell,在滑動時顯示刪除按鈕

UITableViewCell,在滑動時顯示刪除按鈕

iOS
HUWWW 2019-09-18 10:42:07
如何在滑動時顯示刪除按鈕UITableViewCell?永遠不會引發該事件,并且永遠不會出現刪除按鈕。
查看完整描述

3 回答

?
DIEA

TA貢獻1820條經驗 獲得超2個贊

在啟動期間(-viewDidLoad or in storyboard)執行:


self.tableView.allowsMultipleSelectionDuringEditing = NO;

覆蓋以支持表視圖的條件編輯。如果您要返回NO某些項目,則只需要實現此功能。默認情況下,所有項目都是可編輯的。


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

    // Return YES if you want the specified item to be editable.

    return YES;

}


// Override to support editing the table view.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        //add code here for when you hit delete

    }    

}


查看完整回答
反對 回復 2019-09-18
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

此代碼顯示了如何實現刪除。


#pragma mark - UITableViewDataSource


// Swipe to delete.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [_chats removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }

}

(可選)在初始化覆蓋中,添加以下行以顯示“編輯”按鈕項:


self.navigationItem.leftBarButtonItem = self.editButtonItem;


查看完整回答
反對 回復 2019-09-18
  • 3 回答
  • 0 關注
  • 945 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號