objective-c - uiactionsheet 崩溃

标签 objective-c ios uiactionsheet

我有一个操作表,其工作原理如下:

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

相关文章:

ios - UIPageViewController 和不同的 View Controller

ios - 具有 Unix 计算机时间值的 NSDateFormatter

objective-c - 在类型 'myArray' 的对象上找不到属性 'MyVC *' Swift 到 Obj-C 传递数组错误

android - Android 的 XML 文件是否与 iOS Xcode 的 Storyboard做同样的事情?

ios - 在 viewDidAppear 之前获取 scrollView 的内容大小

ios - 在 iPad App 中动态加载 3D 模型

ios - 将 NSNumber 转换为 Boolean 会为 iPhone 和 iPad 提供不同的结果

objective-c - 多个 UIActionSheets 一次打开

iphone - uiactionsheet 点击在操作表底部不起作用的非常奇怪的错误

ios - UIPopover 如何使用这样的按钮制作弹出窗口?