UIKit

iOS UITableView插入新数据和删除数据

2017-02-04  本文已影响328人  小辉辉___

UITableView插入新数据

//插入到第0行
NSArray *insertIndexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone]; // 插入新row
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];

UITableView删除数据

[self.resultFrame removeObjectAtIndex:[indexPath row]];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; //删除对应数据的cell
[self.tableView endUpdates];
上一篇下一篇

猜你喜欢

热点阅读