我剛開了這些,而我分析我的代碼:方法返回一個+1 Objective-C的對象保留計數
Method returns an Objective-C object with a +1 retain count
和
Object leaked: object allocated and stored into 'headerLabel' is not referenced later in this execution path and has a retain count of +1
這種方法
:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(15.0, 0.0, 300.0, 44.0)];
// create the button object
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:15];
headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
if (section == 0)
headerLabel.text = NSLocalizedString(@"A", @"A");
else if (section == 1)
headerLabel.text =NSLocalizedString(@"B", @"B");
else if (section == 2)
headerLabel.text = NSLocalizedString(@"C", @"C");
if(searching)
headerLabel.text = NSLocalizedString(@"SEARCH", @"Search Results");
[customView addSubview:headerLabel];
return customView;
}
現在,擴大我試圖理解上的箭頭,我想是是customView不是DEA llocated。這樣對嗎?
我該如何解決這個問題?我是新手,幫助我理解!
,如果你不使用ARC,添加autorelease到customView初始化或返回[contentView autorelease];由於viewForHeader方法意味着視圖應該被自動釋放。 – Eugene 2012-02-07 18:22:08
謝謝,我嘗試了你的建議,現在它的工作原理!沒有更多的泄漏 – Phillip 2012-02-07 18:30:16