从AppDelegate外部调用放置在AppDelegate中的UIActionSheet

时间:2012-03-01 16:23:31

标签: iphone objective-c uiactionsheet uiapplicationdelegate uiwindow

我的AppDelegate中有一个UIActionSheet,由:

调用
- (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的范围内无效,但应该是,对吧?毕竟,我可以毫无问题地在self.tabBarController.selectedSegmentIndex = N中执行AnotherViewController之类的操作。

我甚至尝试更改showActionSheet:,以便最后一行是[sheet showFromView:self.window]。当然我的_window应该可以全球访问吗?

我显然缺少一些基本的东西,但我不确定它是什么。

1 个答案:

答案 0 :(得分:0)

您确定AppDelegate符合UIActionSheetDelegate协议吗?