UINavigationController from scratch?

家住魔仙堡 提交于 2020-01-17 03:28:07

问题


I have a view based app that works well. (In other words, I'm not going to start over with a Navigation-Based App template.)

It's an immersive app of sorts and I'm trying to add a Table View that loads in a new view when a button is pressed.

The loading the nib part works, but I can't seem to be able to add a navigation controller to the new view. I want to see a navigation bar on top with a done button and an edit button. Also, I want to the Table View entries to be empty.

  • I added a new file like so: File-> New File -> UINavigationController subclass. I checked the UITableViewController Subclass and With XIB for user interface.

All I see when the view is pulled up is a blank Table View. I am able to customize things in the view controller.

What can I do to make the table show a navigation bar and be editable? I need some direction here please.

EDIT: I'm working with the latest Public SDK. (XCode 3.2.2)


回答1:


The navigation bar usually comes with a navigation controller, not with the table view controller.

You can add the navigation bar manually, but that will require altering the table view, to change it to just a regular view with a table view inside of it, and changing your table view controller to be a regular view controller that manually handles the table view stuff.

The simpler alternative is to wrap your table view controller inside of a navigation controller before you display it. Something like:

MyTableViewController *myViewController = [[MyTableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[myViewController release];

//Now display navigationController instead of myViewController, using something like:
[self presentModalViewController:navigationController animated:YES];


来源:https://stackoverflow.com/questions/2886269/uinavigationcontroller-from-scratch

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