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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:37:12  来源:igfitidea点击:

UINavigationController popViewControllerAnimated: crash in iOS 6

iphoneobjective-cxcodeuitableviewios6

提问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 UITableViewControllerthat 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 tableViewis 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];(YESrather 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 UIViewControllerthat'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, popViewControllerAnimatedwill 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 modeand then resolving all the compiler warnings/error fixed it automatically.

Enabling ARC mode然后解决所有编译器警告/错误自动修复它。