开发者

iPhone Obj C - 2nd XIB How to configure a Nav Controller and View Controller

Still learn开发者_开发知识库ing Obj-C slowly... forgive the dumb questions...

On my 1st XIB I have the App Delegate, Nav Controller and several view controllers. Along with that I have several buttons that calls a 2nd or 3rd or subsequent XIB.

The subsequent XIBS all have buttons which display views.

So on the 2nd+ XIB I have configured it in the .h as an UIViewController however I am guessing I need to make it something else like the primary .h is an AppDelgate.

So right now the XIB wants the view set, but I don't want it to go to a view, I want it to go to the view controller... I think??

Maybe I am still going about this all wrong. I need the primary menu to call the next menu (2nd XIB) which in turn calls various views. In my Java Android app I have about 70 classes, and guess and about 45 views so I am guessing again that I do in fact need the multiple XIBS.

So the question is how do I set up the additional XIBs? Are they AppDelegates or what?

Does that change the way I call the 2nd XIB?


The XIBs or the UIViews (or it's subclasses) are just the facial make up.

For the actually programming part, you deal directly among the "controllers" classes for these views.

View controllers that you make can have an XIB attached to them. But the behavior of how and when the view is shown or hidden, is all handled by the view controller itself.

So to come to the point, if you want to have a navigation bar on the top of you app (assuming that it's a simple app wanting to show many views with a navigation bar):

Create a UINavigationController instance in your applicationDidFinishLaunching: method in the app delegate:

// Assuming that mainViewController is the first controller + view for your app.
navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
[window addSubview:navigationController.view];

This will automatically add a navigation bar to your views. You don't need to add them manually in XIB or anywhere else. Now how you draw/implement mainViewController, is up to you.


When you want to show another view from within mainViewController, you should call:

AnotherViewController *anotherViewController = [[[AnotherViewController alloc] init] autorelease];
[self.navigationController pushViewController:anotherViewController animated:YES];

This will "push" your new view (from anotherViewController instance) into your navigation structure, which will automatically add a back button on the top.


Hope this helps clear the scene of how it works, a bit.

If you have doubts, comment about it. Have a great day!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜