iOS - Calling App Delegate method from ViewController

前端 未结 13 867
鱼传尺愫
鱼传尺愫 2020-11-28 00:29

What I am trying to do is click a button (that was created in code) and have it call up a different view controller then have it run a function in the new view controller.

相关标签:
13条回答
  • 2020-11-28 01:36

    A lot of good answers are already added. Though I want to add something which suits me most of the time.

    #define kAppDelegate ((YourAppDelegate *)[[UIApplication sharedApplication] delegate]);
    

    and thats it. Use it throughout the application just like a constant.

    e.g.

    [kAppDelegate methodName];
    

    Don't forget to import yourAppDelegate.h in corresponding .pch or macros file.

    0 讨论(0)
提交回复
热议问题