這是我的我的UITableViewiPhone:UITableView泄漏像泰坦尼克號!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identificadorNormal = @"Normal";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:identificadorNormal];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identificadorNormal] autorelease];
UILabel * myText = [[[UILabel alloc] initWithFrame:CGRectMake(5.0, 54.0, 225, 18)] autorelease];
[myText setTextAlignment:UITextAlignmentLeft];
[myText setBackgroundColor:[UIColor whiteColor ]];
[myText setClipsToBounds:YES];
[myText setFont:[UIFont systemFontOfSize:14.0]];
[myText setTextColor:[UIColor blackColor]];
[myText setAlpha:0.6];
[myText setTag: 1];
[cell addSubview:myText];
UILabel * labelFRE = [[[UILabel alloc] initWithFrame:CGRectMake(235.0, 54.0, 80, 18)] autorelease];
[labelFRE setTextAlignment:UITextAlignmentCenter];
[labelFRE setBackgroundColor:[UIColor greenColor ]];
[labelFRE setClipsToBounds:YES];
[labelFRE setFont:[UIFont boldSystemFontOfSize:14.0]];
[labelFRE setTextColor:[UIColor blackColor]];
[labelFRE setAlpha:0.75];
[labelFRE setTag: 2];
[cell addSubview:labelFRE];
}
cell.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat: @"table%d", indexPath.row] ofType:@"jpg"]];
NSString * preffix = [NSString stringWithFormat: @"grat%d", indexPath.row];
UILabel *myText2 = (UILabel*)[cell viewWithTag:1];
[myText2 setText:NSLocalizedString(preffix, @"")];
UILabel *labelFRE2 = (UILabel*)[cell viewWithTag:2];
[labelFRE2 setText:NSLocalizedString(@"frKey", @"")];
return cell;
}
這是漏水就像地獄的cellForRowAtIndexPath的代碼。每當我滾動表格時,更多的泄漏被添加到樂器列表中。
你們能找到原因嗎?
感謝您的任何幫助。
編輯
第一輪徵求意見後,我已經改變了以前的代碼這個
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identificadorNormal = @"Normal";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier: identificadorNormal];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identificadorNormal] autorelease];
UILabel * myText = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 54.0, 225, 18)];
[myText setTextAlignment:UITextAlignmentLeft];
[myText setBackgroundColor:[UIColor whiteColor ]];
[myText setClipsToBounds:YES];
[myText setFont:[UIFont systemFontOfSize:14.0]];
[myText setTextColor:[UIColor blackColor]];
[myText setAlpha:0.6];
[myText setTag: 1];
[cell addSubview:myText];
[myText release];
UILabel * labelFRE = [[UILabel alloc] initWithFrame:CGRectMake(235.0, 54.0, 80, 18)];
[labelFRE setTextAlignment:UITextAlignmentCenter];
[labelFRE setBackgroundColor:[UIColor greenColor ]];
[labelFRE setClipsToBounds:YES];
[labelFRE setFont:[UIFont boldSystemFontOfSize:14.0]];
[labelFRE setTextColor:[UIColor blackColor]];
[labelFRE setAlpha:0.75];
[labelFRE setTag: 2];
[cell addSubview:labelFRE];
[labelFRE release];
}
cell.imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat: @"table%d", indexPath.row] ofType:@"jpg"]];
NSString * preffix = [NSString stringWithFormat: @"grat%d", indexPath.row];
UILabel *myText2 = (UILabel*)[cell viewWithTag:1];
[myText2 setText:NSLocalizedString(preffix, @"")];
UILabel *labelFRE2 = (UILabel*)[cell viewWithTag:2];
[labelFRE2 setText:NSLocalizedString(@"frKey", @"")];
return cell;
}
泄漏繼續。根本沒有改變。
它報告的泄漏對象是什麼?你有NSZombieEnabled嗎? – coneybeare 2009-10-27 23:40:17
它報告「GeneralBlock-16(16字節)GraphicsServices PurplePushEvent和CreateWithEventRecord ... – SpaceDog 2009-10-27 23:49:56
你能看到這些泄漏的調用堆棧嗎? – coneybeare 2009-10-28 00:10:38