美文网首页UIKit
iOS UITableView插入新数据和删除数据

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

作者: 小辉辉___ | 来源:发表于2017-02-04 11:13 被阅读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];

相关文章

网友评论

    本文标题:iOS UITableView插入新数据和删除数据

    本文链接:https://www.haomeiwen.com/subject/mepjittx.html