UIDatePicker 泄漏 [英] UIDatePicker leaks

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

问题描述

我似乎有一个泄漏的 UIDatePicker.我已经注意到用于设置 datePickerMode 以显示日期和时间的内存泄漏.但是,我只是想显示日期.我相当确定这是一个框架泄漏,因为当我注释掉几个 UIDatePicker 属性分配时,泄漏就会消失.这段代码泄漏了 1 个 CGColor 对象和 1 个 UIDeviceRGBColor 对象:

I appear to have a leaky UIDatePicker. I have noted memory leaks for setting the datePickerMode to show date and time. But, I'm only trying to display date. I'm fairly certain this is a framework leak because when I comment out several UIDatePicker property assignments, the leaks go away. This code leaks 1 CGColor object, and 1 UIDeviceRGBColor object:

datePicker = [[UIDatePicker alloc] initWithFrame:[self detailViewRect]];


datePicker.datePickerMode = UIDatePickerModeDate; //leaks CGColor when setting this
datePicker.hidden = NO;
datePicker.timeZone = [NSTimeZone systemTimeZone]; //leaks UIDeviceRGBColor
datePicker.maximumDate = [NSDate date];//leaks UIDeviceRGBColor
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;

通过评论 Instruments 报告的违规行,我没有发现任何泄漏:

By commenting the lines Instruments reported as offending, I get no leaks:

datePicker = [[UIDatePicker alloc] initWithFrame:[self detailViewRect]];

//datePicker.datePickerMode = UIDatePickerModeDate; //leaks CGColor when setting this
datePicker.hidden = NO;
//datePicker.timeZone = [NSTimeZone systemTimeZone]; //leaks UIDeviceRGBColor
//datePicker.maximumDate = [NSDate date];//leaks UIDeviceRGBColor
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;

如果至少没有设置日期模式,UIDatePicker 就毫无价值.有没有人有解决方法?

Without at least date mode set, the UIDatePicker is worthless. Does anyone have a workaround?

推荐答案

这种方法对我有用:

在 xib 中创建 DatePicker 而不是编程方法.然后,在 Attributes Inspector 上,将 Mode 设置为 Date.

Create the DatePicker in xib instead of the programmatic approach. Then, on the Attributes Inspector, set Mode to Date.

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

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