2012-07-29 52 views
0

我在AppDelegate应用程序didFinishLaunchingWithOptions中添加了以下代码,以引用我在故事板中创建的UITabBarController(如选项卡式应用程序模板)。然后,我想self.currentController突然当前选项卡(ViewController)。我可以把它reprecent这样的标签之一,并在日志获取视图控制器的名称self.currentController:引用到故事板中的当前选项卡UITabBarController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController; 
self.currentController = [[tabController viewControllers] objectAtIndex:0]; 
} 

但如何使它reprecent的目前dislplayed标签?

我已经试过:

self.currentController = tabController.selectedViewController 

我得到警告:不兼容的指针分配给的UIViewController < BannerViewContainer>从UIViewController中。 如果我NSLog self.currentController现在它说(空)。

我也尝试了UITabBarController class reference的代码的不同组合,但我无法使它工作。什么是正确的代码呢?

回答

1

您正在寻找tabController.selectedViewController

+0

如果我写self.currentController = tabController.selectedViewController我得到警告:不兼容的指针分配给的UIViewController 从UIViewController中。如果我NSLog self.currentController它是(空)。 – ingenspor 2012-07-29 19:45:49

+0

你的控制器对象被称为SubViewContainer我拿它?您可能需要投影视图控制器'self.currentController =(SubViewContainer *)tabController.selectedViewController;' – Sam 2012-07-30 00:25:10

相关问题