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

发布于 2024-12-05 08:47:17 字数 1081 浏览 0 评论 0原文

我想切换到另一个viewController。我的视图上有一个 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 意味着存在内存问题,但我不明白,因为自动引用计数器已打开。

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

提前致谢 :)

I want to switch to another viewController. I have an UIButton on my view, the UIButton have an UILongPressGestureRecognizer by using this code:

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

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

[NewButton addGestureRecognizer:buttonLongPressRecognizer];

The action I use to switch viewControllers are this:

- (IBAction)LoadButtonSettings:(id)sender {

[ButtonSettingsViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

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

}

The problem is that when I make a long press on the button my app crashes and gives me a SIGABRT error. Weirdly enough it only happens on my iPhone, not on the simulator.

I have also tried using

    [self presentModalViewController:ButtonSettingsViewController animated:YES];

and got the same problem. As I know SIGABRT means there's a memory issue, which I don't understand since Automatic Reference Counter is on.

Any ideas on how to fix this?

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

负佳期 2024-12-12 08:47:17

如果 ButtonSettingsViewController 是视图控制器的类型,您需要首先初始化它:

- (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];
}

If ButtonSettingsViewController is the type of view controller you need to initialize it first:

- (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];
}
丑疤怪 2024-12-12 08:47:17

PresentModalViewController:animated: 需要一个视图控制器对象。您向它传递一个类(ButtonSettingsViewController)。首先实例化视图控制器对象:

ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];

然后设置该视图控制器对象的 modalTransitionStyle 属性:

viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

然后呈现它:

[self presentModalViewController:viewControllerObject animated:YES];

presentModalViewController:animated: requires a view controller object. You're passing it a class (ButtonSettingsViewController). First instantiate the view controller object:

ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];

Then set the modalTransitionStyle property of that view controller object:

viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

Then present it:

[self presentModalViewController:viewControllerObject animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文