【发布时间】:2015-05-01 01:29:47
【问题描述】:
我有一个这样的操作表:
- (void)Method1 {
UIActionSheet *photoSourceSheet=[[UIActionSheet alloc]
initWithTitle:@"Options"
delegate:self
cancelButtonTitle:@"Exit"
destructiveButtonTitle:nil
otherButtonTitles:@"opt1",@"opt2", @"opt3", nil];
photoSourceSheet.tag=1;
photoSourceSheet.delegate=self;
[photoSourceSheet showInView:self.view];
}
- (void)Method2 {
UIActionSheet *photoSourceSheet1=[[UIActionSheet alloc]
initWithTitle:@"Select Video"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take New Video", @"Choose Existing Video", nil];
// photoSourceSheet.delegate=self;
photoSourceSheet1.tag=2;
photoSourceSheet1.delegate=self;
[photoSourceSheet1 showInView:self.view];
}
那么在我的委托中我有:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex: NSInteger)buttonIndex {
if (actionSheet.tag==1) {
if (buttonindex==2) {
[self method2];
}
} else if (actionSheet.tag==2) {
// some code
}
}
我的委托方法被调用为第一个操作表,即 photoSourceSheet,但不是为 photoSourceSheet1。
我需要做一些特别的事情吗,比如手动关闭工作表?
我的第二个UIActionSheet (photoSourceSheet1) 出现了,但只要我在工作表上选择一个选项,它就会使应用程序崩溃。
它抛出 EXEC_BAD_ACCESS
【问题讨论】:
-
向我们展示您的
// some code,因为它看起来像在那里崩溃 =) -
就像我说的那样,它永远不会进入“某些代码”,因为不会调用委托方法..
-
你怎么知道的?断点?
-
您是否尝试过手动关闭工作表? (我没有检查它是否可行,但你建议它,这似乎是合理的。)
-
我刚刚意识到..由于我使用的是委托方法 didDismissWithButtonIndex ,所以在调用方法 2 之前必须关闭第一张工作表?对吗?
标签: objective-c ios uiactionsheet