简体   繁体   中英

Iphone: Unable to return back from navigation bar controller

I have a very simple question. I have a view controller. In the view controller, i have added few buttons. On button click I have to start a tab bar controller (each of which has navigation controller).

Code Snippet:

- (IBAction) pushNewsAlertsController:(id)sender {

   //Create a navigation controller
   UINavigationController *FirstNavController = [[UINavigationController alloc] init] ;

   //create the view controller (table view controller)
   FirstViewController *firstViewController = [[FirstViewController alloc] init];

   [FirstNavController pushViewController:firstViewController animated:YES];


   //Create a navigation controller
   UINavigationController *secondNavController = [[UINavigationController alloc] init] ;

   //create the view controller (table view controller)
   SecondViewController *secondViewController = [[SecondViewController alloc] init];
   [secondNavController pushViewController:secondViewController animated:YES];

   // Set the array of view controllers
   tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil] ;

   //Add the tab bar controller's view to the window
   [self.view addSubview:tabBarController.view];
}

I am able to add the tabviews and navigation controller. The problem is I am unable to get back to the main view once the button is clicked.

Can anyone guide me on how to get back to the previous view so that I can click other buttons.

In this case, I would consider presenting the tab bar controller modally. It's a cleaner way of organizing your views in the same way the user interface is organized. You can just dismiss the modal presentation to go back to the previous view. Read View Controller Programming Guide for iOS about similar advice and examples.

Not sure if I get what you are trying to do, but if you want the tab bar controller view to disappear again, the only way would be the inverse of

[self.view addSubview:tabBarController.view];

which could be

[tabBarController.view removeFromSuperview];

I must say it looks like an odd construction you're building, but it may work nevertheless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM