[英]How to delete a row from table view IOS
我想從表視圖中刪除一行而不使用下面的數據源方法。 怎么做?
- (void) tableView : (UITableView *)tableView
commitEditingStyle : (UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath : (NSIndexPath *)indexPath
怎么樣[UITableView deleteRowsAtIndexPaths: withRowAnimation:]
?
(我已經為您鏈接了Apple的文檔鏈接)。
@Scar的想法也很好,但是這將刷新整個表,如果將用戶滾動到表的底部並將其刷新到頂部,這可能會對用戶造成一些干擾。
並不是那么簡單,您必須使用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];
這樣可以防止在更新數組時調用委托方法。
從模型中刪除該行,然后調用-deleteRowsAtIndexPaths:withRowAnimation:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.