我想切换到另一个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/