Here is my experiment:
1. What I would like to do is to manage my app navigation manually so I set
[self.navigationController setNavigationBarHidden:YES];
2. I created a MyFormControllerView which is a contact form actually and will be used for adding and editing contacts. Now when adding a contact my custom navigation bar will have different buttons then that when editing th开发者_高级运维us I created also AddMyFormControllerView and EditMyFormControllerView.
3. Here goes the fun part. I would like from AddMyFormControllerView and EditMyFormControllerView to display a custom header (in this case some buttons) and beneath I would like to show MyFormControllerView.
QUESTION: I assume that I should connect/include MyFormControllerView with/into other controllers through a UIViewController but I don't have luck. How can I do it? Note please that I would like to use the Interface builder as much as possible.
And yes... I know there is no need to have two additional controllers to achieve that. My question is only how can I connect views together.
I'm not sure I fully understand your question, but here's what I think you should do.
Don't have a MyFormControllerView and then embed other view controllers -- that gets too messy and adds unnecessary complexity. Just have AddMyFormControllerView and EditMyFormControllerView like you would if you were using a UINavigationController, but in the -viewWillAppear:
method of the view controllers, add [self.navigationController setNavigationBarHidden:YES];
(as you already are). All that does is hide the navigation bar; everything else about the behavior of the navigation controller is the same (except of course for the fact that you have to allow the user to switch between views, which you are with the custom header).
As for the custom header, just add it to as a subview of the AddMyFormControllerView and EditMyFormControllerView as you would any other view.
From MyFormControllerView
, you can push to EditMyFormControllerView
, and you can present modally AddMyFormControllerView
.
To Push
:
MyFormControllerView *mfcv = [[MyFormControllerView alloc] initWithNib:@"MyFormControllerView" bundle:nil];
[self.navigationController pushViewController:mfcv animated:YES];
To Present Modally
:
EditMyFormControllerView *emfcv = [[EditMyFormControllerView alloc] initWithNib:@"EditMyFormControllerView" bundle:nil];
[self.navigationController presentModalViewController:emfcv animated:YES];
精彩评论