簡體   English   中英

iOS6 UIPickerView內存泄漏問題。

[英]iOS6 UIPickerView memory leak issue.

我得到了這個內存泄漏:

[UIPickerTableViewTitleCell initWithStyle:resuableIdentifier]; 

NSConcentrateMutableAttributedString.

問題是我沒有實現這個委托。 實現這一點后,內存泄漏就消失了。 可能這些信息對其他人有用,因為我花了16個小時來解決這個問題。

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

感謝您的信息。 對此漏洞感到困惑。 只有少數評論:

  • 可能lblRow應該自動釋放: return [lblRow autorelease];

  • [pickerView rowSizeForComponent:component]可用於獲取新標簽的大小。

我在彈出窗口中使用了IUIPicker,每次我解開popover時都會出現內存泄漏。 我也在使用ARC,所以我解決這個問題的最簡單方法是在卸載時設置UIPickerView = nil。 以下似乎已經成功了。

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.pickerView = nil;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM