Switching between different views using only MainWindow.xib
Hey guys, Sorry if I'm a newbie on this xcode interface builder but I need some help on how to switch between different view using only the MainWindow.xib instead of creating more .xib files. Basically, I have a Tab Bar Controller with 3 Tab Bar items and on my 3rd Tab Bar item I have a UIView that contains a UIImageView and has couple of buttons. Now I want these buttons to open up a new view, for example, one of my buttons, I want it to open a Navigation Controller where it contains my mobile blog, and with the back button, I want to return back my 3rd Tab Bar item view.
I've been searching around the Google and YouTube for these kind of help but all they keep saying is creating another .xib view controller file, but not even one talks about creating different views using only the MainWindow.xib. I hope you guys can help me out with this situation and explain to me step by step on how to do this, thanks
A common approach to this problem would be:
Create a navigation view controller by subclassing UINavgationController
to manage the view you want to appear when a button is pressed:
// BlogNavigationController.h
@interface BlogNavigationController : UINavigationController {}
@end
// BlogNavigationController.m
@implementation BlogNavigationController
- (void)viewDidLoad {
//manipulate views here
}
@end
In your button pressed action in your main view controller, you want to then push this navigation controller on to the current stack or present a modal view controller:
// In Button pressed action
BlogNavigationController *blogVC = [[BlogNavigationController alloc] init];
[self.navigationController pushViewController:blogVC animated:YES];
or
// In Button pressed action
BlogNavigationController *blogVC = [[BlogNavigationController alloc] init];
[self presentModalViewController:controller animated:YES];
I'm not sure why you're so reluctant to create a nib file - IB is really just a way of helping you construct your views. Whether you do this in IB or programatically is up to you.
Hope this helps.
精彩评论