我刚开了这些,而我分析我的代码:方法返回一个+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