Call method from initialized UIViewController in storyboarding - objective c

前端 未结 2 2071
旧巷少年郎
旧巷少年郎 2021-01-29 06:17

I\'m new to Storyboarding in objective c and I need to call method from UIVIewController. Before Storyboarding I was initializing UI

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 06:52

    If you want to have this method available from any class you can keep doing the same. Place in in your AppDelegate and then just retrieve the shared instance on the controller you want to use it from. (all your application has access to your appdelegate) so just import the header of the app delegate, create a new instance of your specific appdelegatename class, and call the shared delegate. then you can use the method as if that class would have it.

    Additionaly you can use something like this

    #import "AppDelegate.h"
    #define appDelegate (AppDelegate *) [[UIApplication sharedApplication] delegate]
    

    IF you want to call a method from ANY of your viewcontrollers which are specified in the storyboard you can do it by referencing their identifier:

    PreviewViewController *tmp = [[self storyboard] instantiateViewControllerWithIdentifier:@"PreviewViewController"];
    

提交回复
热议问题