UIPickerView似乎是每次我旋转组件时泄漏 [英] UIPickerView seems to be leaking each time I rotate a component

查看:88
本文介绍了UIPickerView似乎是每次我旋转组件时泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

看起来像是苹果的bug。我尝试了以下操作:

Seems to me like it is pretty much an Apple bug. I tried the following:


  1. 创建一个新的单窗口项目

  2. 创建一个UIPickerView如下所示,只有
    选择器只允许转动表盘。也就是说,当与选择器交互时,变量
    或任何状态都不被操作。

结果:无论我是使用简单的titleForRow:forComponent还是viewForRow:forComponent,每次拨号时,选择器仍然会泄漏48个字节。此外,我甚至试图让选择器返回视图先前分配在一个数组设置为viewController的类属性,所以没有视图被保留或释放,但无论选择器可能在调用委托方法之前或之后内部做。

RESULT: No matter whether I use the simple titleForRow:forComponent or viewForRow:forComponent, the picker still leaks 48 bytes each time a dial is turned. Further, I even tried having the picker return views previously allocated in an array set up as a class property in the viewController, so that no views are retained or released but for whatever the picker might do internally after or before it calls the delegate methods. And still, the leaks occur.

似乎像一个苹果的bug给我。

Seems like an Apple bug to me.

ORIGINAL QUESTION

我有一个textField,其imputView设置为一个UIPickerView有4个组件。选择器用于选择成为textField中文本的重量/质量。

I have a textField whose imputView is set to a UIPickerView with 4 components. The picker is used to select a weight / mass which becomes the text in the textField.

在Instruments下,每次转动UIPickerView中的拨盘/组件时,发生:

Under Instruments, each time I turn a dial / component in the UIPickerView, a leak occurs:


这是48字节泄漏的堆栈跟踪:

Here's the stack trace for the 48 byte leak:

UIPickerView获取每个组件视图的代码是:

The code through which the UIPickerView gets each component view is:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if(!view)
    {
        view = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 37)] autorelease];
        UILabel *label = (UILabel*)view;
        label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        label.textAlignment = UITextAlignmentCenter;
        label.font = [UIFont boldSystemFontOfSize:24];
        label.backgroundColor = [UIColor clearColor];
    }

    ((UILabel*)view).text = [NSString stringWithFormat:@"%@%i", ((component == 3) ? @"." : @""), row];
    return view;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return  60;
}

将textField更新为新文本值的代码是:

And the code that updates the textField to the new textual value is:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSString *newWeight = [NSString stringWithFormat:@"%i%i%i.%i", 
                           [pickerView selectedRowInComponent:0], 
                           [pickerView selectedRowInComponent:1],
                           [pickerView selectedRowInComponent:2],
                           [pickerView selectedRowInComponent:3]];

    self.sampleMassBuffer = [NSDecimalNumber decimalNumberWithString:newWeight];
    weightTextField.text = [[numberFormatter stringFromNumber:self.sampleMassBuffer] stringByAppendingFormat:@" %@", currentConfiguration.weightUnits];
}



我不知道泄漏是如何产生的,
它是一个苹果bug吗?

I have no idea how the leaks are originating or if they are even mine! Could it be an Apple bug?

推荐答案

SDK中的漏洞。我只是用一个信任的来源确认。

The leak in the SDK. I just confirmed with a trusted source.

这篇关于UIPickerView似乎是每次我旋转组件时泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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