我有以下问题:
我有一个 AppDelegate,我添加了一个 navigationController 并在其中加载 UIViewController B。
在 B 中,我添加一个 navigationItem、一个 leftBarButtonItem 或一个 rightBarButtonItem。
我必须在哪里释放这些项目,因为我在B中分配和初始化它们。所以一开始我想到了在B的Dealloc-Method中释放self.navigationItem.rightBarButtonItem。
但是如果我正在分析我的应用程序,分析器会在 B 的 dealloc 方法中的释放位置处显示:
Incorrect decrement of the reference count of an object that is not owned at this point by the caller.
但我不明白我做错了什么,还是一切正常,这是分析器问题?
有人可以帮我查一下吗?
问候安迪1984
最佳答案
一旦分配并分配给 rightBarButtonItem,您就可以像这样释放
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
[rightBarButtonItem release];
与 leftBartButtonItem 类似
self.navigationItem.rightBarButtonItem 本身可能有一个保留,并且知道何时释放该计数。
关于ios - 释放一个navigationItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7262764/