一、自已以語法的方式建立。
/* * ExampleAppDelegate.h */ @interface ExampleAppDelegate : NSObject{ UIWindow *window; UITabBarController *mainBar; UINavigationController *firstNav; UINavigationController *secondNav; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) UITabBarController *mainBar; @property (nonatomic, retain) UINavigationController *firstNav; @property (nonatomic, retain) UINavigationController *secondNav; @end
2、在 ExampleAppDelegate.m 寫上下面的語法
/*
* ExampleAppDelegate.m
*/
#import "ExampleAppDelegate.h"
#import "FirstView.h"
#import "SecondView.h"
@implementation ExampleAppDelegate
@synthesize window;
@synthesize mainBar;
@synthesize firstNav;
@synthesize secondNav;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
firstNav = [[UINavigationController alloc] init];
FirstView *firstView = [[FirstView alloc] init];
[firstNav pushViewController:firstView animated:YES];
firstNav.tabBarItem.title = @"First Tab";
[firstView release];
secondNav = [[UINavigationController alloc] init];
SecondView *secondView = [[SecondView alloc] init];
[secondNav pushViewController:secondView animated:YES];
secondNav.tabBarItem.title = @"Second Tab";
[secondView release];
mainBar = [[UITabBarController alloc] init];
mainBar.viewControllers = [NSArray arrayWithObjects:
firstNav, secondNav, nil];
[self.window addSubview:mainBar.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc { [firstView release]; [secondView release]; [mainBar release]; [window release]; [super dealloc]; }二、以 xib 的方法建立可以參考 http://blog.willwinder.com/2011/05/xcode4-uitabbarcontroller-with.html特要注意的是要在 view 也拉一個 UINavigationControll,然後把UIView 和 UINavigationControll全建立個link 到 ViewController.h檔裡面,然後在 VieDidLoad加上下列的語法:在這邊我把UIView取名為theParentViewOutlet,UINavigationController取名為 navigationController。這樣的用意是可以取代原本的navigationController。就不用改太多了。[self.theParentViewOutlet addSubview:self.navigationController.view];以上的資料參考下面兩個網址:1、http://ppkko.blogspot.tw/2011/05/tabbarcontroller-navigationcontroller.html2、http://stackoverflow.com/questions/5163024/uinavigationcontroller-inside-uiview
沒有留言:
張貼留言