0

我想在UITabbarViewController完全加載並顯示在屏幕上時收到通知?iPHone - 檢測UITabBarController委託方法?

因爲它是從UIViewController繼承我試圖設置委託給我的appdelegate和實現viewDidAppear,但它永遠不會被調用。

任何解決方案?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.tabbar.delegate = self; 
    //other stuff 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    NSLog(@"asdasd"); 
} 
+0

你想完成什麼? – Anna 2011-04-28 21:00:49

回答

0

當你設置一個UITabBarController的委託,你將只能覆蓋UITabBarControllerDelegate方法而不是UITabBarController方法。

解決方案:

從代碼

解決方案創建的UITabBarController:乙

子類的UITabBarController

對於這兩種解決方案,你可以做你內的viewDidLoad代碼或發送NSNotification與信息該視圖已完全加載。

0

我不認爲這是一個非常優雅的解決方案,但你可以使用NSNotificationCenter

[[NSNotificationCenter defaultCenter] postNotificationName:myNotification object:self]; 

張貼通知,並對此作出迴應如下:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dosomething:) name:myNotification object:nil]; 
+0

這是如何告訴我何時加載標籤欄? – aryaxt 2011-04-28 20:34:22

0

使用從UIViewController繼承的UITabBarController的viewDidAppear。控制器負責視圖的生命週期,而不是委託人。

+0

你能否提供更多的細節,它似乎不像UITabBarController包含任何UITabViewController。 – aryaxt 2011-04-28 21:03:09

+0

當然,UITabBarController是UIViewController的一個子類。這意味着您可以訪問UIViewController的方法,包括viewDidLoad:,viewDidAppear:等。根據您使用UITabBarController的方式,您應該能夠覆蓋相關的方法來完成您的任務。 – jakev 2011-04-28 21:27:45