当我使用故事板在XCode 4中创建一个TabBarController的iPhone模板时,它会自动配置主视图控制器等一切内容。但是在AppDelegate中没有Tab Bar Controller的属性。我可以为它创建一个输出口,并尝试将其与我的故事板中的Tab Bar Controller链接起来,但这是不可能的。是否有更好的方法在didFinishLaunchingWithOptions方法中访问Tab Bar Controller,因为它已经被连接了呢?我想要的是self.currentController = Tab Bar Controller中的当前选项卡。
AppDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m:
@interface AppDelegate()
@property (nonatomic, assign) UIViewController<SubViewContainer> *currentController;
@end
@synthesize window = _window
@synthesize currentController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//I need this piece of code to equal the Tab Bar Controller current tab
self.currentController = ?
return YES;
}
//And I'm gonna use this void for some statements about the Tab Bar Controller tabs:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:
(UIViewController *)viewController
{
// with some statements
}
selectedViewController
属性。这是您所询问的吗? - Phillip Mills