开发者

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 i开发者_JS百科s 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜