Hi Everyone,
Here is the code that I currently have.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
static NSInteger CountTag = 1;
static NSInteger PlaceTag = 2;
static NSInteger TimeTag = 3;
NSData* imageData;
UIImage* imageForData;
UIImageView* imageView;
//CellWithId *cell = (CellWithId*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
CellWithId * cell = [[CellWithId alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
//}
CGRect frame;
frame.origin.x = 5;
frame.origin.y = 0;
frame.size.height = 43;
frame.size.width = 52;
if ([[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]!=[NSNull null]) {
//This is the line flagged as leaking.
imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]]];
imageForData = [[UIImage alloc] initWithData:imageData];
imageView = [[UIImageView alloc] initWithImage:imageForData];
imageView.frame = frame;
[cell.contentView addSubview:imageView];
[imageData release];
[imageForData release];
}else {
//imageForData = [UIImage imageNamed:@"Plans-Default-image.jpg"];
imageForData = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Plans-Default-image" ofType:@"jpg"]];
imageView = [[UIImageView alloc] initWithImage:imageForData];
imageView.frame = frame;
[cell.contentView addSubview:imageView];
}
[imageView release];
imageData = nil;
imageForData = nil;
frame.origin.x = 10;
cell.accessoryType = UITableViewCellStateShowingDeleteConfirmationMask ;// AccessoryDetailDisclosureButton;
cell.cellRelatedId = [[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"id"] intValue];
frame.origin.x = 75;
frame.origin.y = 5;
frame.size.height = 15;
frame.size.width = 200;
UILabel *placeLabel = [[UILabel alloc] initWithFrame:frame];
placeLabel.tag = PlaceTag;
[cell.contentView addSubview:placeLabel];
[placeLabel release];
//frame.origin.y += 18;
// UILabel *countLabel = [[UILabel alloc] initWithFrame:frame];
// countLabel.tag = CountTag;
// [cell.contentView addSubview:countLabel];
// [countLabel release];
frame.origin.y += 18;
UILabel *timeLabel = [[UILabel alloc] initWithFrame:frame];
timeLabel.tag = TimeTag;
[cell.contentView addSubview:timeLabel];
[timeLabel release];
if ([[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"me_too"] intValue] == 0) {
frame.origin.x = 35;
if (selectedButton!=1) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.text = [NSString stringWithFormat:@"%d", cell.cellRelatedId];
button.titleLabel.hidden = YES;
[button setFrame:CGRectMake(254.0f, 5.0f, 30.0f, 40.0f)];
UIImage *img = [UIImage imageNamed:@"metoo.jpeg"];
[button setImage:img forState:UIControlStateNormal];
[img release];
//[button setTitle:@"D" forState:UIControlStateNormal];
[button addTarget:self action:@selector(meToo:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
}
}
//}
// Set up the cell...
// cell.text = [NSString stringWithFormat:@"State: %@ Capital: %@",[capitals objectAtIndex:indexPath.row],[states objectAtIndex:indexPath.row]];
//UILabel * placeLabel = (UILabel *) [cell.contentView viewWithTag:PlaceTag];
//UILabel * countLabel = (UILabel *) [cell.contentView viewWithTag:CountTag];
//UILabel * timeLabel = (UILabel *) [cell.contentView viewWithTag:TimeTag];
placeLabel.font = [UIFont boldSystemFontOfSize:15];
//countLabel.font = [UIFont boldSystemFontOfSize:12];
timeLabel.font = [UIFont boldSystemFontOfSize:12];
placeLabel.text = [[planDictionary objectAtIndex:indexPath.row] objectForKey:@"name"];
//countLabel.text = [NSString stringWithFormat:@"%@ People", [[[planDictionary objectForKey:@"plans"] objectAtIndex:indexPath.row] objectForKey:@"peopleCount"]];
timeLabel.text = [[planDictionary objectAtIndex:indexPath.row] objectForKey:@"planTime"];
//[placeLabel release];
//[timeLabel release];
return cell;
}
The code indicated above is a place where it shows memory leak.