Xcode:为什么我使用presentModalViewcontroller 收到SIGABRT 消息?
我想切换到另一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 ButtonSettingsViewController 是视图控制器的类型,您需要首先初始化它:
If ButtonSettingsViewController is the type of view controller you need to initialize it first:
PresentModalViewController:animated: 需要一个视图控制器对象。您向它传递一个类(ButtonSettingsViewController)。首先实例化视图控制器对象:
然后设置该视图控制器对象的 modalTransitionStyle 属性:
然后呈现它:
presentModalViewController:animated: requires a view controller object. You're passing it a class (ButtonSettingsViewController). First instantiate the view controller object:
Then set the modalTransitionStyle property of that view controller object:
Then present it: