0

私は tabBarController を使用して写真を表示し、各種類の写真が各タブに表示されるため、1 つの ViewController.xib を使用し、各タブに異なるコンテンツ (ナビゲーション項目と ImageView) を表示する方法は?

私の質問は次のとおりです。次のステップでコードを書く場所と方法は、コードは -(void)tabBarController または PhotoController.m ですか? –</p>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *photoController1 = [[[PhotoController alloc] initWithNibName:@"PhotoController" bundle:nil] autorelease];
UIViewController *photoController2 = [[[PhotoController alloc] initWithNibName:@"PhotoController" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: 
                                         ,photoController1
                                         ,photoController2
                                         ,nil];
self.tabBarController.delegate=self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{       
    switch (tabBarController.selectedIndex) 
{
    case 4:     
        //how to write code;
        break;
    case 5:
        //how to write code;
    default:
        break;
    }
}
4

1 に答える 1

0

PhotoController でいくつかの準備メソッドを作成し、それを公開して、tabBarController didSelectViewController から呼び出すことができるため、コードは次のようになります。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {       
    switch (tabBarController.selectedIndex)  {
    case 4:     
            //configure options for photoController
            [viewController prepareForDisplayWithOptions:options];
        break;
    case 5:
            //configure options for photoController2
            [viewController prepareForDisplayWithOptions:options2];
        break;
    default:
        break;
    } 

}

于 2012-04-27T07:44:27.557 に答える