Search code examples
objective-ciosuiviewcontrollerpushviewcontrollerpresentmodalviewcontroller

Add NavigationController to current view


I'm using a UIScrollView to display some images, and i need to present or push another view when the user selects one part of the image.This ScrollView is created only programmatically. How i can programmatically add a navigationController to it and present another view?

I tried this way but just give me the following error :

Pushing a navigation controller is not supported'

 StatesViewController * controller = [[StatesViewController alloc]initWithNibName:@"StatesViewController" bundle:nil];

    UINavigationController * Navcontroller = [[UINavigationController alloc] initWithRootViewController:controller];

    [self presentModalViewController: Navcontroller animated: YES];

Solution

  • this might help you.

     NextViewController *nextViewController=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
        UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:nextViewController];
        [self.navigationController presentModalViewController:navBar animated:YES];