我有一个操作表,其工作原理如下:
- (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
}
}
我的委托(delegate)方法被第一个操作表调用,即 photoSourceSheet,但不是 photoSourceSheet1。
我需要做一些特别的事情吗,比如手动关闭工作表?
我的第二个 UIActionSheet
(photoSourceSheet1) 出现,但一旦我在工作表上选择一个选项,它就会使应用程序崩溃。
它抛出 EXEC_BAD_ACCESS
最佳答案
上面的代码没有任何问题。 EXEC_BAD_ACCESS 基本上是由于内存管理不良造成的。有时您会无意中删除正在使用的对象。 尝试启用僵尸,它会告诉您确切的问题区域。
步骤:转到编辑方案 内存管理 选中选项启用僵尸对象
关于objective-c - uiactionsheet 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12921460/