尝试了解 NavigationController 在其堆栈上保留 ViewController 的计数
我有一个 UITableViewController 作为我的 navigatorController 的 rootViewController 。 当我按下表格单元格时,我会执行以下操作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MessageHistory *msg = (MessageHistory *)[[self fetchedResultsController]objectAtIndexPath:indexPath];
ConversationViewController *chatController = [[ConversationViewController alloc]initWithNibName:@"ConversationView" bundle:nil andUser:msg.user];
[self.navigationController pushViewController:chatController animated:YES];
[chatController release];
但是当我从 chatController 返回时(使用导航栏上的后退按钮),我得到“EXC_BAD_ACCESS”
评论
//[chatController release];
解决了问题。如何?我认为当推送到 navigationController 时会添加一个保留计数,当从它弹出时会释放它?
另外,我相信如果我在推送到导航控制器后不包含发布,我就会产生泄漏。
知道这里发生了什么吗?
I have an UITableViewController as the rootViewController for my navigatorController.
When I press a table cell I do the following:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MessageHistory *msg = (MessageHistory *)[[self fetchedResultsController]objectAtIndexPath:indexPath];
ConversationViewController *chatController = [[ConversationViewController alloc]initWithNibName:@"ConversationView" bundle:nil andUser:msg.user];
[self.navigationController pushViewController:chatController animated:YES];
[chatController release];
But when I'm returning from the chatController (using the back button on the navbar) I get “EXC_BAD_ACCESS”
commenting
//[chatController release];
solves the problem. How? I thought when pushing to the navigationController adds a retain count and when pop from it release it?
Also I believe if I'm not including the release after pushing to the navcontroller I'm generating a leak.
Any idea what's happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经遇到过这个问题好几次了,并且几乎疯狂地试图找到错误。
就我而言,我的第二个视图中有一个 UIWebView,并将 UIViewController 设置为它的委托。在我的 UIViewController dealloc 方法中,我忘记放置 webView.delegate = nil。
当第二个 UIViewController 被弹出并因此被释放时,UIWebView 正在向它的委托(第二个 UIViewController,它不再存在)发送一条消息。
不知道这是否适用于您,但我花了几天时间寻找这个错误,所以也许它有任何帮助。
I've had this problem a few times, and almost went crazy trying to find the error.
In my case, I had a UIWebView in my second view with the UIViewController set as it's delegate. In my UIViewController dealloc method, I forgot to put webView.delegate = nil.
When the second UIViewController was popped and thus deallocated, the UIWebView was sending a message to it's delegate (the second UIViewController, which didn't exist anymore).
Don't know if this applies to you, but I spend days searching for this error, so perhaps it is of any help.