【发布时间】:2017-12-01 17:41:13
【问题描述】:
我有一个不断更新新数据的数据库。我将此数据用作我的UITableView 的数据源。目前,我正在使用NSNotifications 提醒我的UITableView 插入、删除或更新新数据。但是,我一直认为使用delegates 会更好,因为它是一对一的。
这里有一些代码可以更好地演示发生了什么。
- (void)insertObject:(NSNotification *)notification {
NSNumber *object = [notification object];
[self.tableView beginUpdates];
[self.data insertObject:object atIndex:0];
[self.tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:0] withAnimation:NSTableViewAnimationEffectNone];
[self.tableView endUpdates];
}
【问题讨论】:
标签: ios objective-c delegates nsnotificationcenter