Set RootViewController in UINavigationController class - Objective C

89 Views Asked by At

I am new working with Objective C, I have good knowledge with storyboards but now I try to change the root view controller of a UINavigationController by code, it happens that it depends on a variable, I will set the root, but I don't know how to configure this action besides what I have my custom class for my UINavigationControllers. I hope you can help me.Keep in mind that this view is the 3rd screen in the app.

enter image description here

@interface PCCatalogNavigationController () <UINavigationControllerDelegate>

@end

@implementation PCCatalogNavigationController

- (void)viewDidLoad{
    if (status == 1){
        //TableViewViewController
    } else {
        //Optional StarViewController
    }
}

@end
1

There are 1 best solutions below

4
On

inside Your App delegate just add Property of you Navigation Controller

@property (nonatomic , strong) UINavigationController *navigationController;

and Inside

-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

TableViewViewController *TableViewView = [[UIStoryboard
storyboardWithName:@"Main" bundle:nil]
instantiateViewControllerWithIdentifier:@"TableViewViewController"];


StarViewController *StarView = [[UIStoryboard
storyboardWithName:@"Main" bundle:nil]
instantiateViewControllerWithIdentifier:@"StarViewController"];


    if (status == 1){  
    self.navigationController =
    [[UINavigationController alloc]
    initWithRootViewController:TableViewView];  
    } else {  
    //Optional
    StarViewController  self.navigationController =
    [[UINavigationController alloc]
    initWithRootViewController:StarView];  
    }  
}

instead UINavigationController you can use you customNavigationcontroller