Kev*_*vin 2 iphone objective-c uitableview
所以我有一个FirstViewController,它是一个UITableViewController,以及delegate和dataSource.它有桌子视图.
我有另一个类,FeedParser,它解析数据 - 但在完成解析后,我需要它去刷新UITableView,否则它不会显示任何东西.
这可能是一个愚蠢的问题,请原谅我,但我该如何从FeedParser调用FirstViewController的tableView.reloadData?
有没有方法可以返回该视图?
谢谢!
Mat*_*ick 17
注册视图控制器以接收数据已更改的通知,并在收到数据时刷新表.然后让解析器发送出去.
注册它很容易:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourRefreshMethodHere:)
name:@"YourNotificationName"
object:nil];
Run Code Online (Sandbox Code Playgroud)
您需要设置刷新方法以接收这些通知,方法如下:
- (void)reloadTable:(NSNotification *)notif {
[self.yourTableName reloadData];
}
Run Code Online (Sandbox Code Playgroud)
在ViewDidUnload中停止观察非常重要:
[[NSNotificationCenter defaultCenter] removeObserver:self];
Run Code Online (Sandbox Code Playgroud)
然后在解析器中,您只需在完成后添加它:
[[NSNotificationCenter defaultCenter] postNotificationName:@"YourNotificationName"
object:nil];
Run Code Online (Sandbox Code Playgroud)
视图控制器(以及使用该名称观察通知的任何其他人)将获取消息并执行其任务.