首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS6 UIPickerView内存泄漏问题。

iOS6 UIPickerView内存泄漏问题。
EN

Stack Overflow用户
提问于 2012-10-24 16:27:01
回答 2查看 1.4K关注 0票数 6

我得到了这个内存泄漏:

代码语言:javascript
复制
[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier]; 

代码语言:javascript
复制
NSConcentrateMutableAttributedString.

问题是我没有实现这个委托。在实现了这一点之后,内存泄漏现在就消失了。这些信息可能对其他人有帮助,因为我花了16个小时才弄清楚这个问题。

代码语言:javascript
复制
// Do something with the selected row.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

// Get the text of the row.
NSString *rowItem = [NSString stringWithFormat:@"     %@",[machineData objectAtIndex:row]];

// Create and init a new UILabel.
// We must set our label's width equal to our picker's width.
// We'll give the default height in each row.
UILabel *lblRow = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView bounds].size.width, 44.0f)];

// Make the text color red.
[lblRow setTextColor: [UIColor blackColor]];
[lblRow setFont:[UIFont boldSystemFontOfSize:20]];

// Center the text.
[lblRow setTextAlignment:UITextAlignmentLeft];

// Add the text.
[lblRow setText:rowItem];

// Clear the background color to avoid problems with the display.
[lblRow setBackgroundColor:[UIColor clearColor]];

// Return the label.
return lblRow;
}
EN

回答 2

Stack Overflow用户

发布于 2012-11-01 00:02:08

感谢您的信息。被这次泄密搞糊涂了。只有几条评论:

可以使用return [lblRow autorelease];

  • [pickerView rowSizeForComponent:component]来获取新标签的大小。

可能应该自动发布lblRow。

票数 0
EN

Stack Overflow用户

发布于 2013-04-20 21:19:26

我在弹出窗口中使用了IUIPicker,每次关闭弹出窗口时都会发生内存泄漏。我也在使用ARC,所以我解决这个问题的最简单的方法是在卸载时设置UIPickerView = nil。下面的代码似乎已经完成了这项工作。

代码语言:javascript
复制
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.pickerView = nil;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13045423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档