我使用下面的代码制作了一个UITabBarController:
在AppDelegate.h
内:
IBOutlet UITabBarController *rootController;
...
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
在AppDelegate.m中
@synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
现在我需要知道如何在AppDelegate中实现这个方法:
- (void)SwitchToTab:(int)index{
//go to tabview 1 or 2 ...
}
答案 0 :(得分:4)
你可以这样做:
self.rootController.selectedIndex = 2; // or whatever index you like
或者这个:
self.rootController.selectedViewController = oneOfTheViewControllersInTheTabController;
有关详细信息,请参阅UITabBarController reference page。