0

外我有我的一個的AppDelegate UIActionSheet被名爲:調用UIActionSheet被放置在AppDelegate中從AppDelegate中

- (void)showActionSheet { 
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Call Lilly" otherButtonTitles:@"Email IMCLONE Trials", @"Email EmergingMed", nil]; 
    [sheet showFromTabBar:self.tabBarController.tabBar]; 
} 

我需要從AnotherViewController調用它。在控制器中我有:

[(LYAppDelegate *)[[UIApplication sharedApplication] delegate] showActionSheet]; 

...並且這不起作用。我得到的錯誤:

[3990:207] *** Assertion failure in -[UIActionSheet _presentSheetFromView:above:], /SourceCache/UIKit_Sim/UIKit-1912.3/UIActionSheet.m:1747 

我假設的問題是,參考self.tabBarController.tabBar是不是在AnotherViewController範圍內有效,但它應該是吧?畢竟,我可以在AnotherViewController之內做任何事情,例如self.tabBarController.selectedSegmentIndex = N

我甚至試過改變showActionSheet:以便最後一行是[sheet showFromView:self.window]。當然我的_window應該可以全球訪問?

我很明顯錯過了一些基本的東西,但我不確定它是什麼。

回答

0

你確定你的AppDelegate符合UIActionSheetDelegate協議嗎?

+0

是的,我已經通過在'LYAppDelegate'中調用'showActionSheet'來測試它。 – 2012-03-01 16:38:02

+0

你有沒有確定你是從主線程調用它? – deleterOfWorlds 2012-03-01 16:40:19

+0

我會不得不做任何不尋常的事情來從主線程調用它?我使用'didSelectRowAtIndexPath'從'AnotherViewController'調用它。沒有Web服務調用,沒有任何異步進行。我應該做些什麼來確保它是從主線程調用的? – 2012-03-01 16:44:40