Ios 从多个自定义段展开到根控制器时崩溃
我需要实现定制的segue,它最多可以堆叠三次,然后通过整个堆栈将其放回到根视图控制器 以下是我的segue的代码:Ios 从多个自定义段展开到根控制器时崩溃,ios,objective-c,iphone,Ios,Objective C,Iphone,我需要实现定制的segue,它最多可以堆叠三次,然后通过整个堆栈将其放回到根视图控制器 以下是我的segue的代码: - (void)perform { UIViewController* sourceViewController = self.sourceViewController; UIView* firstVCView = [(UIViewController*)self.sourceViewController view]; UIView* secondVC
- (void)perform {
UIViewController* sourceViewController = self.sourceViewController;
UIView* firstVCView = [(UIViewController*)self.sourceViewController view];
UIView* secondVCView = [(UIViewController*)self.destinationViewController view];
// Get the screen width and height.
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight);
// Access the app's key window and insert the destination view above the current (source) one.
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window insertSubview:secondVCView aboveSubview:firstVCView];
[UIView animateWithDuration:0.5 animations:^{
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0);
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0);
} completion:^(BOOL finished) {
[sourceViewController.navigationController presentViewController:self.destinationViewController animated:NO completion:nil];
}];
}
对于展开段:
- (void)perform {
UIViewController* sourceViewController = self.sourceViewController;
UIView* secondView = [(UIViewController*)self.sourceViewController view];
UIView* firstView = [(UIViewController*)self.destinationViewController view];
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window insertSubview:firstView aboveSubview:secondView];
[UIView animateWithDuration:0.5 animations:^{
firstView.frame = CGRectOffset(firstView.frame, screenWidth, 0);
secondView.frame = CGRectOffset(secondView.frame, screenWidth, 0);
} completion:^(BOOL finished) {
[sourceViewController.navigationController dismissViewControllerAnimated:NO completion:nil];
}];
}
对于单一过渡,一切都很好——我可以轻松地前进和后退。
但是,当我向前进行两次或两次以上的转换,然后尝试向后退绕时,即使在任何代码调用之前按下与退绕序列相关联的按钮,也会发生以下错误:
2015-08-28 18:40:37.460 ProjectName[17807:973012] *** -[UIStoryboardUnwindSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x7fbd4bc717d0
显然这是最后一个控制器丢失了。
但如果我在内存中锁定它和整个上一个控制器堆栈,那么除了方法调用“prepareforsgue”之外,什么也不会发生:没有调用其他委托方法,没有抛出异常,没有执行转换。
另外,当所有控制器都被锁定在内存中时,我尝试调用popToRootViewControllerAnimated和其他类似的方法——也没有任何结果
我已经没有办法解决这个问题,也没有办法在整个互联网上找到解决方案。我怎样才能修好它 这一行的自定义序列中出现了问题:
[sourceViewController.navigationController presentViewController:self.destinationViewController animated:NO completion:nil];
我应该按ViewController而不是presentViewController:
[sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO];
现在,当我改变它时,一切都像一个符咒。希望它能帮助别人