0

我使用 tabBarController 来显示照片,每种照片都显示在每个选项卡中,所以我使用一个 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 中创建一些 prepare 方法,并将其公开,这样您就可以从 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 回答