How to launch a ViewController from a Non ViewController class?

后端 未结 7 2024
星月不相逢
星月不相逢 2020-12-22 09:48

the title says it all, i usually open ViewControllers like this

ListingViewController *listingView = [[ListingViewController alloc]init];
[self.navigationCon         


        
7条回答
  •  余生分开走
    2020-12-22 10:12

    self.navigationController can be accessed via only UIViewController's subclass. You want to access UINavigationController from not UIViewcontroller class. Is it what you are asking?

    If you have property of UINavigationController at AppDelegate like

    @interface AppDelegate : UIResponder 
    @property (strong, nonatomic) UIWindow *window;
    @property (strong, nonatomic) UINavigationController *navigationController;
    @end
    

    You can get a pointer from wherever you want as below

    #import "AppDelegate.h"
    AppDelegate *delegate = (AppDelegate *)[[[UIApplication sharedApplication] delegate];
    UINavigationController *navigation = [delegate navigationController];
    

    Now you have it.

提交回复
热议问题