如果问题标题准确,请提前道歉。我在下面概述了我想要实现的基本流程。
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, SomeFrameworkDelegate, OtherFrameworkDelegate>
…other init stuff
AppDelegate.m
SomeFrameworkDelegate
和OtherFrameworkDelegate
方法。 MainViewController
DetailsViewController
备注:
我假设我要在AppDelegate中设置全局变量,然后在其他UI代码中,我将创建AppDelegate的实例:
AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.isConnected = ...
appDelegate.serviceName = ...
如何检测消息何时到达委托方法? NSNotificationCenter / NSTimer?
即。触发委托方法后发布通知或创建计时器以轮询appDelegate中的变量。
答案 0 :(得分:1)
听起来您正在尝试处理/管理应用程序委托中的连接。 AppDelegate的目的是响应应用程序级事件,例如applicationdidbecomeactive / applicationwillenterforeground。我的建议是你创建一个单例来管理你的连接。这通常称为sharedInstance模式。这个单例应该实现managedObject的委托函数。实施后你有几个选择。
在这种情况下,我建议您使用NSNotification,因为您正在尝试找出连接状态更改。如果您希望收到对象属性的每次更改的通知,那么您应该使用KVO。
答案 1 :(得分:0)
你真的回答了自己的问题。我会使用NSNotificationCenter
在委托方法触发时发布通知。然后,在视图控制器中,观察该通知并进行响应。