How do I add the UIApplicationDelegate to the end of the UIResponder chain?

浪尽此生 提交于 2019-12-04 07:32:26

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.

Starting with iOS 5, the AppDelegate is automatically the last link in the responder chain. Xcode project templates will create an AppDelegate that is a subclass of UIResponder rather than NSObject. However, to avoid cluttering up the AppDelegate, override the AppDelegate's nextResponder and offload work into a custom UIResponder object:

- (UIResponder *)nextResponder
{
    static dispatch_once_t onceToken;
    static LastUIResponder *lastResponder = nil;
    dispatch_once(&onceToken, ^{
        lastResponder = [[LastUIResponder alloc] init];
    });
    return lastResponder;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!