故事板中的当前选项卡

时间:2012-07-30 17:00:14

标签: iphone objective-c xcode uitabbarcontroller

如果我使用storybard创建一个Tab Bar应用程序项目模板并将其放在我的AppDelegate.m中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"Root: %@", self.window.rootViewController);
NSLog(@"Current ViewController: %@", /*self.window.rootViewController.selectedIndexOrSomething?*/  );
return YES;
}

它说:Root:< UITabBarController:0x6b20360>

所以我猜TabBarController已经添加为window属性的subView,因为我没有以任何其他方式触及AppDelegate而不是NSLog。

如何记录当前标签/ ViewController?

1 个答案:

答案 0 :(得分:0)

你会想要这样做:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"Root: %@", self.window.rootViewController);
    NSLog(@"Current ViewController: %@", ((UITabBarController *)self.window.rootViewController).selectedViewController );
    return YES;
}