2016-05-30 23 views
1

刪除所有選定行我知道這個電話,將刪除選定的行:的Objective-C從UITableView中

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

我的問題是,我該如何刪除所有選定的行?因爲我有多個選擇。

感謝,

+0

我認爲唯一的辦法是遍歷所有行和取消他們! –

+0

'indexPathsForSelectedRows'返回'NSIndexPath'的'NSArray'。那麼循環和取消選擇行呢? – Larme

回答

1

如果你問行取消你可以做這樣的:

NSArray *selectedIndexPaths = [tableView indexPathsForSelectedRows]; 

    [tableView beginUpdates]; 

    [selectedIndexPaths enumerateObjectsUsingBlock:^(NSIndexPath *selectedIndexPath, NSUInteger idx, BOOL * _Nonnull stop) { 

     [tableView deselectRowAtIndexPath:selectedIndexPath animated:NO]; 

    }]; 

    [tableView endUpdates]; 
+0

這沒有奏效,所選行仍保持不變。 – user979331

+0

@ user97931我剛剛在一個測試項目上檢查了這個方法,一切正常。你可以分享你的代碼,以便我們看到問題出在哪裏...... – Seliver

0

您可以使用deleteRowsAtIndexPaths(_:withRowAnimation :)與選定indexPaths。

此外,你必須從你的數據源中刪除你的對象。

+0

OP需要取消選擇不刪除它們的行。 –

0

使用此:

[self.tableView reloadData];