0

我有一个这样的操作表:

- (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

4

1 回答 1

1

上面的代码没有任何问题。EXEC_BAD_ACCESS 基本上是由于内存管理不善造成的。有时您无意中删除了正在使用的对象。尝试启用僵尸它会告诉你确切的问题区域。

步骤: 进入 Edit Scheme Memory Management 检查选项enable Zombie Objects

于 2012-10-16T19:41:47.713 回答