Xcode:为什么我使用presentModalViewcontroller 收到SIGABRT 消息?

标签 xcode memory presentmodalviewcontroller sigabrt automatic-ref-counting

我想切换到另一个viewController。我的 View 上有一个 UIButton,UIButton 使用以下代码有一个 UILongPressGestureRecognizer:

UILongPressGestureRecognizer *buttonLongPressRecognizer;
buttonLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LoadButtonSettings:)];

buttonLongPressRecognizer.numberOfTouchesRequired = 1;
buttonLongPressRecognizer.minimumPressDuration = 2.0;

[NewButton addGestureRecognizer:buttonLongPressRecognizer];

我用来切换 viewController 的操作是这样的:

- (IBAction)LoadButtonSettings:(id)sender {

[ButtonSettingsViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[self presentViewController:ButtonSettingsViewController animated:YES completion:NULL];

}

问题是,当我长按按钮时,我的应用程序崩溃并给出 SIGABRT 错误。奇怪的是,它只发生在我的 iPhone 上,而不是模拟器上。

我也尝试过使用

    [self presentModalViewController:ButtonSettingsViewController animated:YES];

也遇到了同样的问题。据我所知,SIGABRT 意味着存在内存问题,但我不明白,因为自动参​​考计数器已打开。

关于如何解决这个问题有什么想法吗?

提前致谢:)

最佳答案

如果 ButtonSettingsViewController 是 View Controller 的类型,您需要先初始化它:

- (IBAction)LoadButtonSettings:(id)sender {
    // init & alloc - Replace with your custom view controllers initialization method (if applicabale)
    ButtonSettingsViewController *viewController = [[ButtonSettingsViewController alloc] initWithNibNamed:@"ButtonSettingsViewController" bundle:nil];

    [viewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentViewController:viewController animated:YES completion:NULL];
}

关于Xcode:为什么我使用presentModalViewcontroller 收到SIGABRT 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7464751/

相关文章:

linux - 并行运行 top 和 free-m 命令

ios - 通过 TabBarController 呈现模态视图 Controller

ios - xcode 7 警告 : Null passed to a callee that requires a non-null argument

xcode - 我无法在 Swift 中调用 Account Kit 的委托(delegate)方法

xcode - 无法更新命令行工具,因为Xcode告诉我我无权访问它们

PHP exec() 使用内存

memory - 现代 Linux 中是否有 NUMA 下次接触策略

ios - Q :Controller present 2 second ,如何让它看起来只有一个转换?

objective-c - 应用程序试图以模态方式呈现事件 Controller : UIImagePickerController

ios - 无法关闭模态视图 Controller