【发布时间】:2012-05-09 22:42:50
【问题描述】:
下面的代码会有多错:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
for (id currentObject in array) {
if ([currentObject isKindOfClass:[self class]]) {
self = [currentObject retain];
}
}
return self;
}
我正在尝试从 nib 文件中调出一个自定义 UITableViewCell,问题是 Leaks Instruments 说里面有泄漏:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CPVideoGenTVCell *cell = (CPVideoGenTVCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CPVideoGenTVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.delegate = self;
cell.titleLbl.textColor = [UIColor colorWithRed:0.992 green:0.933 blue:0.0 alpha:1.0];
}
CPTempVideo *aVideo = [self.videos objectAtIndex:indexPath.row];
cell.seasonLbl.text = [NSString stringWithFormat:@"Season %@", [self romanNumberFromArabic:aVideo.season]];
cell.titleLbl.text = [NSString stringWithFormat:@"%2i - \"%@\"",aVideo.idVideo, aVideo.chapterName];
cell.managedImg.url = aVideo.thumbnail;
[[CPDataManager sharedDataManager] manageImage:cell.managedImg];
return cell;
}
【问题讨论】:
-
显示您的
cellForRowAtIndexPath:代码。 -
你运行
Analyze了吗?它可能会为您提供泄漏位置的线索。 -
分析没有显示任何东西......我认为这段代码“应该”工作,但它可疑......
标签: ios memory-leaks uitableview xib