xcode UINavigationController popViewControllerAnimated:在 iOS 6 中崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12570799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UINavigationController popViewControllerAnimated: crash in iOS 6
提问by Anthony
The code below works fine in iOS 4 and 5 but crashes in iOS 6 with EXC_BAD_ACCESS
. I'd appreciate any help in troubleshooting it. This code is being called in a UITableViewController
that handles my app's search logic:
下面的代码在 iOS 4 和 5 中运行良好,但在 iOS 6 中使用EXC_BAD_ACCESS
. 我很感激在故障排除方面的任何帮助。正在UITableViewController
处理我的应用程序搜索逻辑的代码中调用此代码:
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
The way I add the tableView
is similar and doesn't crash when called:
我添加的tableView
方式类似,调用时不会崩溃:
SearchTVC *searchTable = [[SearchTVC alloc] init];
searchTable.detailViewController = self.detailViewController;
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:searchTable animated:NO];
What could be the problem?
可能是什么问题呢?
*EDIT
*编辑
Interestingly the crash doesn't occur if I use [self.navigationController popViewControllerAnimated:YES];
(YES
rather than NO
). But of course this defeats the purpose of using a custom pop animation.
有趣的是,如果我使用[self.navigationController popViewControllerAnimated:YES];
(YES
而不是NO
),则不会发生崩溃。但这当然违背了使用自定义流行动画的目的。
采纳答案by Anthony
I know my question was vague, but I didn't have much else to go off of. I knew the line [self.navigationController popViewControllerAnimated:NO];
was the problem but I couldn't figure out why. Then I came across this questionand the first answer suggested I make my search table an instance variable rather than creating a new one every time I want to present it, and that actually worked. It must be a memory issue that I can't wrap my head around.
我知道我的问题含糊不清,但我没有什么可说的。我知道线路[self.navigationController popViewControllerAnimated:NO];
有问题,但我不知道为什么。然后我遇到了这个问题,第一个答案建议我让我的搜索表成为一个实例变量,而不是每次我想展示它时都创建一个新的,这确实有效。这一定是我无法理解的记忆问题。
tl;dr:
tl;博士:
Make sure the UIViewController
that's being pushed and popped is an instance variable.
确保UIViewController
被推送和弹出的是一个实例变量。
回答by LPG
Check whether you have a line like the following somewhere in your view controller code:
检查您的视图控制器代码中是否有如下一行:
self.navigationController.delegate=self;
If so, then you must set it back
如果是这样,那么您必须将其重新设置
self.navigationController.delegate=nil;
before you say
在你说之前
[self.navigationController popViewControllerAnimated:YES];
Otherwise, popViewControllerAnimated
will first deallocate the delegate and then try to call it - resulting in a crash.
否则,popViewControllerAnimated
将首先释放委托,然后尝试调用它 - 导致崩溃。
回答by jeet.chanchawat
Though super late to party... Hope this might help someone in future. I opened a very old code...
虽然聚会超级迟到......希望这可能会在未来对某人有所帮助。我打开了一个非常旧的代码...
Enabling ARC mode
and then resolving all the compiler warnings/error fixed it automatically.
Enabling ARC mode
然后解决所有编译器警告/错误自动修复它。