How to add navigation controller programmatically?

最后都变了- 提交于 2019-12-05 02:24:28

问题


In my app there is requirement that..I have 6 buttons in a nib, when I press any button a new nib will be loaded into the window according to the button pressed. problem is after loading the new nib If I want to come back to the previous nib (which is having all the buttons) how to add navigation controller?

what I am doing now is while loading the new nib when I pressed the button

objNewViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[self.navigationController pushViewController:objNewViewController animated:YES];

but by this way im not able to load the nib, it's not performing any operation?


回答1:


UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]];

[self presentModalViewController:navigationController               animated:YES];
            [navigationController release];

And in NewViewController: USe this to dismiss and get back to previous view.

[[self navigationController] dismissModalViewControllerAnimated:YES];



回答2:


There is a template in Xcode for a navigation based app. It does everything you describe. Well, very close at least, only the AnotherViewController in -tableView:didSelectRowAtIndexPath: is commented out.



来源:https://stackoverflow.com/questions/2415525/how-to-add-navigation-controller-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!