![](/img/trans.png)
[英]Moving a 'UITabBarController with UINavigationController' iPhone app to 'UITabBarController with UISplitView' on iPad
[英]UINavigationController app to a UITabBarController app
我一直在研究基於UINavigationController的應用程序,使用UITableView作為根視圖,使用Core Data作為數據源。
不幸的是,我沒有很好地提前計划,現在我想在我已經擁有的東西上實現標簽欄導航到應用程序。
任何人都可以推薦一種簡單的方法嗎? 或者我最好再次使用基於TabBar的模板並嘗試插入我現有的代碼?
多謝你們!
亞當
您可能只想創建一個基於標簽欄的應用程序並查看它生成的代碼,然后嘗試在您的應用程序中執行相同的操作,而不是重新開始。
您可能只需要更改應用程序委托的application:didFinishLaunchingWithOptions:
方法看起來像這樣:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableArray *viewControllers = [[[NSMutableArray alloc] init] autorelease];
// First tab
MyController *myController = [[[MyController alloc] init] autorelease];
mapViewController.navigationItem.title = @"First";
UINavigationController *myRootController = [[[UINavigationController alloc]
initWithRootViewController:myController]
autorelease];
myRootController.tabBarItem.title = @"First";
myRootController.tabBarItem.image = [UIImage imageNamed:@"MyControllerTab"];
[viewControllers addObject:myRootController];
// Second tab
MyOtherController *myOtherController = [[[MyOtherController alloc] init] autorelease];
myOtherController.navigationItem.title = @"Second";
UINavigationController *otherRootController = [[[UINavigationController alloc] initWithRootViewController:myOtherController] autorelease];
otherRootController.tabBarItem.title = @"Second";
otherRootController.tabBarItem.image = [UIImage imageNamed:@"OtherControllerTab"];
[viewControllers addObject:otherRootController];
// Create other tabs
// ...
// Tab bar
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
[tabBarController setViewControllers:viewControllers];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
如果要將現有導航控制器插入選項卡欄上的其中一個選項卡,則非常簡單 - 只需定義一個新的UITabBarController作為根控制器,並將其加載到單個選項卡中。 然后更改您的app委托以加載標簽欄控制器而不是導航控制器。
但是,如果要從現有導航堆棧中提取多個控制器,則可能需要做更多工作 - 找到調用pushViewController:animated:
地方pushViewController:animated:
修改導航堆棧,然后將這些視圖控制器實例插入標簽欄上的標簽。 這里可能值得從一個新的標簽欄模板開始並復制現有的控制器,具體取決於代碼的復雜程度。
亞當,
不知道你已經完成了多少編碼,但是如果你不熟悉在IB中連接東西並設置代理,你可能最好重新開始使用TabBarController模板。
這是你做的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.