我偶然发现了一个问题,我必须从单例 TCPConnection
类更新 View Controller 类中的数据源。我在单例 TCPConnection
类中有服务器的回调函数,但是当我收到数据时,我必须在 View Controller 类中更新 TableView 的数据源。您能否针对这种情况提供解决方案,在此先感谢。
最佳答案
我将使用 NSNotificationCenter
:
订阅服务(订阅者):
[[NSNotificationCenter defaultCenter] addObserver:<your_controller>
selector:@selector(method)
name:@"name_of_notification"
object:<any_linear_object_u_want>];
现在发送者将发布NSNotificationCenter
:
[[NSNotificationCenter defaultCenter] postNotificationName:@"name_of_notification" object:<any_linear_object_u_want>];
在接收者选择器你可以调用
[self.your_table reloadData];
reloadData
操作可能很繁重,如果您遇到任何性能问题,请尝试其他重新加载。
祝你好运
关于ios - 从单例类中随时了解 View Controller 类中 TableView 的数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566940/