Getting a reference to the UIApplication delegate

后端 未结 2 1127
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 12:41

I\'m writing my first iPhone application and I\'m having trouble switching views. I have 2 views and a reference to each in the AppDelegate (an instance of

相关标签:
2条回答
  • 2020-12-28 12:48

    Use:

    [[UIApplication sharedApplication] delegate];
    
    0 讨论(0)
  • 2020-12-28 12:59

    Yes, UIApplication is a singleton, and uses the normal singleton pattern for Objective-C:

    [UIApplication sharedApplication];
    

    You can get your delegate class directly from it:

    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    0 讨论(0)
提交回复
热议问题