IOS 4.3 UINavigationBar tintColor Leaks [英] IOS 4.3 UINavigationBar tintColor Leaks

查看:176
本文介绍了IOS 4.3 UINavigationBar tintColor Leaks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IOS4.3中,如果我设置

In IOS4.3 if I set

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

我会收到内存泄漏:UIDeviceRGBColor泄漏

I will get a memory leak: UIDeviceRGBColor leak

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

But if I use navigationBar.tintColor = [UIColor blackColor]; Everything is fine.

这在ios4.2中从未发生过

This never happened in ios4.2

我做了一些调试,我找到了 [navigationBar.tintColor retainCount] 如果我使用

I did some debug, and I found the [navigationBar.tintColor retainCount] seems bigger if I use

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

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

Does anyone have the same issue?

这是泄漏代码:

在RootViewController中:

This is the leak code:
In RootViewController:

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

在DetailViewController中:

In 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泄漏

If you go to DetailViewController, then popback to RootViewController, in the Instruments, you can see the UIDeviceRGBColor leak

推荐答案

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

Ive had this issue before 4.2, i think colourWithRed:Green:blue allocates a new UIColor object which your responsible for managing.

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

The solution is to create an instance for your tint colour and release it when your done with your navigation controller in viewDidUnload.

- (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;
}

这篇关于IOS 4.3 UINavigationBar tintColor Leaks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆