ios - 释放一个navigationItem

标签 ios code-analysis navigationcontroller navigationitem

我有以下问题:

我有一个 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/

相关文章:

javascript - 如何在 PhoneGap 中验证无互联网访问权限?

ios - 管理每个用户的 Xcode 命令行工具版本

iphone - NSNotification ...正确的方法?

ios - 在表格 View 中显示多个单元格时出现问题

c# - 在构造函数中访问已实现的抽象属性会导致 CA2214 : Do not call overridable methods in constructors

PHP_CodeSniffer、PHPMD 或 PHP 依赖

visual-studio-2015 - 代码分析错误未出现在 VS2015 Update1 的错误列表中

swift - 删除后如何向快速导航栏添加边框

iphone - iOS:如何在没有任何可见用户界面的情况下正确使用导航 Controller

ios - UINavigation PushViewController 不显示下一个 View ,而是运行代码