2012-08-09 28 views
0

我想從表視圖刪除一行而不使用下面的數據源方法。怎麼做?如何從表視圖中刪除一行IOS

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

刪除源('NSArray')的行,然後重新加載tableView。我認爲這將是工作。 – Scar 2012-08-09 04:32:15

回答

2

[UITableView deleteRowsAtIndexPaths: withRowAnimation:]怎麼樣?

(我已經鏈接了Apple的文檔鏈接爲你)。

@ Scar的想法也不錯,但會刷新整個表格,如果用戶滾動到表格的最下方並將其刷新到頂部,那麼可能會對用戶造成一些干擾。

+0

我將如何獲得索引路徑? – Feroz 2012-08-09 04:33:57

+0

你必須創建它。如果你知道該行,就像[「'NSIndexPath * myIndexPath = [NSIndexPath indexPathForRow:rowNumber inSection:sectionNumber];'](https://developer.apple.com/library/ios/documentation/UIKit/Reference/ NSIndexPath_UIKitAdditions/Reference/Reference.html#// apple_ref/occ/clm/NSIndexPath/indexPathForRow:inSection :)(並且我也爲你鏈接了這個文檔) – 2012-08-09 04:35:46

+0

你說得對,謝謝你將它描述給用戶。 – Scar 2012-08-09 04:38:21

1

從模型中刪除該行並致電-deleteRowsAtIndexPaths:withRowAnimation:

3

並非那麼簡單,你必須有一個UITableView

[_tableView beginUpdates]; // <-- pretty important 

long selectedRow = _tableView.selectedRow; 

[_tableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:selectedRow] withAnimation:NSTableViewAnimationSlideUp]; 

//then remove your object from the array 
[((NSMutableArray*) _searchResults) removeObjectAtIndex:selectedRow]; 

[_tableView endUpdates]; 

原子做到這一點這可以防止當陣列正在更新被稱爲委託方法。