This is the code of my cellForRowAtIndexPath of my 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;
}
This is leaking like hell. Every time I scroll the table, more leaks are added to the list on instruments.
Can you guys spot why?
thanks for any help.
EDIT
After the first round of comments, I have changed the previous code to this
- (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;
}
leaks continue. No change at all.