[英]tableView:editActionsForRowAtIndexPath: getting a nil indexPath
我已經實現了tableView:editActionsForRowAtIndexPath:
函數,但是我間歇地indexPath
傳遞給該函數的indexPath
為nil。 當我嘗試訪問indexPath.row
,其值為18446744073709551615。
我正在查詢用於構建表的數組中的對象。 並崩潰-- -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 1]'
在某些情況下,我使用[table reloadData]
的editAction調用重新加載了表,然后傳遞了nil indexPath,但是這種情況仍然斷斷續續地發生。
有什么辦法可以強制將正確的indexPath傳遞給tableView:editActionsForRowAtIndexPath:
您必須實現此- (void)tableView:(UITableView *)tableView commitEditingStyle
方法,其中需要調整數據數組。
有關詳細信息,請參見本文插入和刪除行和節
您可以通過以下方法處理此問題:首先從data
數組中刪除與該行相對應的項,然后將deleteRowsAtIndexPaths:withRowAnimation:發送到表視圖。
嘗試在下面的代碼行中插入- (void)tableView:(UITableView *)tableView commitEditingStyle
方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( editingStyle== UITableViewCellEditingStyleDelete) {
// remove item from array at first
[dataArray removeObjectAtIndex:indexPath.row];
// then delete table row from tableview
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
希望它能工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.