0

3つのタブを含むTabbarコントローラーを備えたアプリがあります。最初のタブにナビゲーションコントローラーを追加する必要があります。私のルートViewコントローラーはタブバーですが、ナビゲーションバーを追加するにはどうすればよいですか?ナビゲーションバーを初期化しましたが、どこに設定すればよいかわかりません。あなたがより多くの情報を必要とするかどうか助けて尋ねることができる誰かに感謝します。これは私のアプリデリゲートです。m:

#import "TACAppDelegate.h"
#import "FirstViewController.h"
#import "ThirdViewController.h"
#import "SecondViewController.h"

@implementation TACAppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions
{
/* Initialize window view */
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

/* Initialize tab bar controller, add tabs controllers */
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [self initializeTabBarItems];
self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];
return (YES);
}

....

- (NSArray *)initializeTabBarItems
{
NSArray * retval;

/* Initialize view controllers */
FirstViewController *viewController1 = [[FirstViewController alloc] init];
SecondViewController *viewController2 = [[SecondViewController alloc] init];
ThirdViewController *viewController3 = [[ThirdViewController alloc] init];

/* Initialize navigation controllers */
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];



/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,nil];



return (retval);
}

@end
4

1 に答える 1

1

これは、コードでこれを行うために変更する必要がある行です。

/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,nil];

ここでは、元のviewController1への参照をタブバーアイテムの配列に配置しています。それはもはやあなたが望むものではありません。ナビゲーションコントローラーを既に作成し、そのルートビューコントローラーをビューコントローラー1に設定しました。これが、タブバーアイテムのリストに配置する必要のある最上位の参照です。新しい行は次のようになります。

/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects: navigationController1,viewController2,viewController3,nil];

これにより、次のようなコントローラー階層が作成されます。

TabBar:[NavController:[VC1]、VC2、VC3]

于 2012-07-08T18:24:16.740 に答える