2012-07-29 57 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

相關問題