Xcode:为什么我要使用presentModalViewcontroller获取SIGABRT消息?
我想切换到另一个viewController。我的视图上有一个UIButton,UIButton有一个UILongPressGestureRecognitor,使用以下代码:Xcode:为什么我要使用presentModalViewcontroller获取SIGABRT消息?,xcode,memory,presentmodalviewcontroller,sigabrt,automatic-ref-counting,Xcode,Memory,Presentmodalviewcontroller,Sigabrt,Automatic Ref Counting,我想切换到另一个viewController。我的视图上有一个UIButton,UIButton有一个UILongPressGestureRecognitor,使用以下代码: UILongPressGestureRecognizer *buttonLongPressRecognizer; buttonLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(Lo
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是视图控制器的类型,则需要首先对其进行初始化:
- (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];
}
presentModalViewController:动画:需要视图控制器对象。您正在向它传递一个类(ButtonSettingsViewController)。首先实例化视图控制器对象:
ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];
viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
然后设置该视图控制器对象的modalTransitionStyle属性:
ButtonSettingsViewController *viewControllerObject = [[ButtonSettingsViewController alloc] initWithNibName:@"ButtonSettingsViewController" bundle:nil];
viewControllerObject.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
然后提出:
[self presentModalViewController:viewControllerObject animated:YES];
是的,我刚刚意识到这是因为我在ViewDidLoad中初始化了它。。。但非常感谢:Dyeah刚刚意识到这是因为我在ViewDidLoad中初始化了它。。。但是非常感谢你:D