尝试了解 NavigationController 在其堆栈上保留 ViewController 的计数

发布于 2024-08-30 13:25:10 字数 828 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2024-09-06 13:25:10

我已经遇到过这个问题好几次了,并且几乎疯狂地试图找到错误。

就我而言,我的第二个视图中有一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文