I'm not sure if this is the correct way to create a UITableViewCell in code, but it works perfectly, until I need to reload the table as its returning old cells so not loading the new content.
- (UITableViewCell *)tableView:(UITableView *)tableViewData cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableViewData dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (indexPath.section == 0) {
if ([marker objectForKey:@"imageUrl"]) {
UIView *transparentBackground = [[UIView alloc] initWithFrame:CGRectZero];
transparentBackground.backgroundColor = [UIColor clearColor];
cell.backgroundView = transparentBackground;
UIImageView *buildingView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 100, 100)];
buildingView.image = [self imageWithImage:[ImageManipulator makeRoundCornerImage:[self loadImage:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.qut.edu.au%@", [marker objectForKey:@"imageUrl"]]]] :9 :9]];
[cell addSubview:buildingView];
} else {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 15)];
label.text = @"test";
[cell addSubview:label];
[label release];
}
} else {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 15)];
label.text = @"test";
[cell addSubview:label];
[label release];
}
}
return cell;
}
Basically the cell that gets returned on line 3 is not nil (its the old one), therefore the if statement isn't fired and it returns the old cell. I could load a new cell each time but that will have issues with load and memory usage.
Whats the correct way to do this?