How do we assign an object in a `UINavigationController` without clicking on the ViewController. Object?

How to assign an object in UINavigationController

without clicking an object on it ViewController

. Why do I need this here:

I have only three Segment views

and one of the segments is what I add as subView

:

-(void)Frds{
    [self clearSubView];
    obj = [[Frds alloc]initWithNibName:@"Frds" bundle:nil];
    [obj.view setFrame:CGRectMake(0, 65, 320, 568)];
    [self.view addSubview:obj.view];
}

      

and from the class Frds

on access self.navigationController

. It returns to me nil

and it should be obvious since I didn't click ViewController

on it.

So, How can you access navigationController

in a class Frds

after adding a view of an object of class "Frds" as a "subview" from the forwarding class.

+3


source to share


1 answer


You can add your object frnd View Take in the view object RootViewController . First assign one rootviewcontroller on your navigation controller, then you can easily add your view to it.

To assign a root view controller on a navigation controller:

UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];

      



Use this method to find your root view controller:

UIViewController *rootViewController = self.navigationController.viewControllers[0];

      

+3


source







All Articles