iphone - IOS 4.3 UINavigationBar tintColor 泄漏

标签 iphone objective-c ios4

在IOS4.3中如果我设置

navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];

我会发生内存泄漏:UIDeviceRGBColor 泄漏

但是如果我使用 navigationBar.tintColor = [UIColor blackColor]; 一切都很好。

这在 ios4.2 中从未发生过

我做了一些调试,我发现如果我使用 [navigationBar.tintColor retainCount] 似乎更大

[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];

有没有人遇到同样的问题?

这是泄漏代码:
在 RootViewController 中:

- (void)viewWillAppear:(BOOL)animated { 
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        [super viewWillAppear:animated];
    } 

在 DetailViewController 中:

- (void)viewWillAppear:(BOOL)animated {
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9 green:0 blue:0 alpha:0];
        [super viewWillAppear:animated];
    } 

如果你转到 DetailViewController,然后弹出到 RootViewController,在 Instruments 中,你可以看到 UIDeviceRGBColor 泄漏

最佳答案

我在 4.2 之前遇到过这个问题,我认为 colourWithRed:Green:blue 分配了一个你负责管理的新 UIColor 对象。

解决方案是为您的色调创建一个实例,并在您完成 viewDidUnload 中的导航 Controller 后释放它。

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    tintBarColor = [UIColor   
                colorWithRed:50.0/255   
                green:134.0/255   
                blue:187.0/255   
                alpha:1];
    self.navigationController.navigationBar.tintColor = tintBarColor;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    [tintBarColor release];
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on     demand.
    // For example: self.myOutlet = nil;
}

关于iphone - IOS 4.3 UINavigationBar tintColor 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383090/

相关文章:

objective-c - 使用 KVO 观察 Objective-C 集合中对象属性的变化

ios - 无法在 iTunes 连接上上传 iOS 应用程序屏幕截图

iphone - 调试时 XCode 调试与发布构建

ios - UILabel 未显示在自定义 UIView 屏幕中

iphone - 文本字段方式中的键盘如何向上移动 View

iphone - 在旋转和移动时交换 UIImageView 的图像会留下原始图像的痕迹

iphone - 在iphone编程中将自定义字体设置为默认字体

ios - iPhone X 安全区域似乎位于不透明工具栏下方

iphone - 如何在具有导航的 Tabbar 应用程序中调用 viewWillDisappear 方法

java - 如何将Android应用程序移植到iOS平台?