我想切换到另一个viewController。我的视图中有一个UIButton,UIButton使用此代码有一个UILongPressGestureRecognizer:
UILongPressGestureRecognizer *buttonLongPressRecognizer;
buttonLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LoadButtonSettings:)];
buttonLongPressRecognizer.numberOfTouchesRequired = 1;
buttonLongPressRecognizer.minimumPressDuration = 2.0;
[NewButton addGestureRecognizer:buttonLongPressRecognizer];
我用来切换viewControllers的动作是:
- (IBAction)LoadButtonSettings:(id)sender {
[ButtonSettingsViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:ButtonSettingsViewController animated:YES completion:NULL];
}
问题是,当我长按按钮时,我的应用程序崩溃并给我一个SIGABRT错误。奇怪的是,它只发生在我的iPhone上,而不是模拟器上。
我也尝试过使用
[self presentModalViewController:ButtonSettingsViewController animated:YES];
并遇到了同样的问题。据我所知,SIGABRT意味着存在内存问题,自启用自动参考计数器以来我无法理解。
有关如何解决此问题的任何想法?
提前致谢:)
答案 0 :(得分:3)
如果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];
}
答案 1 :(得分:2)
presentModalViewController:animated:需要一个视图控制器对象。你传递了一个类(ButtonSettingsViewController)。首先实例化视图控制器对象:
ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];
然后设置该视图控制器对象的modalTransitionStyle属性:
viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
然后呈现它:
[self presentModalViewController:viewControllerObject animated:YES];