如何将UIApplicationDelegate添加到UIResponder链的末尾?
我正在尝试为应用的各个部分提供常用功能的 IBAction
方法。
I'm trying to provide an IBAction
method for common functionality that is required at various parts of the app.
即登录以模态方式实现,如果成功,则会产生通知,允许所有已加载的视图控制器对此事件作出反应(从匿名转换为经过身份验证)
i.e. Login is implemented modally, and if it succeeds results in a notification that allows all loaded view controllers to react to this event (transition from anonymous to authenticated)
@interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
...
}
- (IBAction)loginTapped:(id)sender;
@end
我将该按钮的操作设置为IB中的第一响应者,但是响应者链没有给 MyAppDelegate
一个回应的机会。
I set the action of that button to the First Responder in IB, however the responder chain doesn't give MyAppDelegate
a chance to respond.
我的问题是,我不知道想要在响应者链的各个部分复制该方法,我想将它添加到已经是子类的公共类中。
My problem is that, I don't want to replicate the method at various parts of the responder chain, I would like to add it to a common class that is already a subclass.
UIResponder
链一直到 UIApplication
,但这似乎结束了。我的 UIApplicationDelegate
无法参加。
The UIResponder
chain goes all the way through to the UIApplication
but that seems to be the end. My UIApplicationDelegate
doesn't get to participate.
我想将我的应用委托插入或添加到响应者链!
I want to insert or add my app delegate to the responder chain!
(或找到另一种方法将 UIButton
内部连接到应用程序全范围实现..我想避免继承子类 UITabBarController
或 UIWindow
如果可能的话)
(or find another way to hook up the UIButton
touch-up-inside to an app-wide implementation.. I want to avoid subclassing the UITabBarController
or UIWindow
if possible)
您可以将 UIApplication
子类化为 -nextResponder
如果它是 UIResponder
子类,则返回应用程序委托。然后,您需要将您的调用更改为 UIApplicationMain
以使用您的自定义子类。
You could subclass UIApplication
to have -nextResponder
return the application delegate if it is a UIResponder
subclass. You'll then need to alter your call to UIApplicationMain
to use your custom subclass.
我还没试过我自己,但我想不出这会造成什么直接问题。
I haven't tried this myself, but I can't think of any immediate problems this would cause.