hacker
hacker

Reputation: 8947

accessing the UInavigationcontroller embedded view controller?

I had an iPhone application(with storyboard) in which i am using a view-controller as initialviewcontroller.Then after that i added a view-controller scene and embedded a navigation-controller to it.I want that navigation-controller to be the rootviewcontroller of the window.When i am trying to access that view controller programatically and push another viewcontroller to it the navigation controller is not there,i also getting the warning of scene unreachable on that navigation controller embedded to that view controller.I am trying to achieve it like this

` 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                             bundle: nil];

    UINavigationController *controller =(UINavigationController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Newcontroller"];
    NSLog(@"%@",[controller topViewController]);

    [appdelegate.window setRootViewController:controller];
`  

can anybody help me how to access this navigation controller programatically ?

Upvotes: 0

Views: 911

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

you need to do like

Step-1

Create the custom class of NavigationController , for example NavigationViewController (SubClass of UINavigationController).

Step-2

Assign the class name for that NavigationController in Identity Inspector.

Step-3

Set the Storyboard ID for that class in Identity Inspector Xcode.

Step-4

Finally access the class via Code, for example

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle: nil];

NavigationViewController *controller =(NavigationViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"navigate"];
NSLog(@"%@",[controller topViewController]);

[appdelegate.window setRootViewController:controller];

for example

enter image description here

Upvotes: 1

Related Questions