I’m loading an image in to an UITableView through a simple
cell.imageView.image = [UIImage imageNamed:@"prem.jpg"];
However, what I’ve learnt from my limited time with xcode things arent normally that easy! I want to have the image in there take up the fullsize of the image which is about 280 wide and 150 tall. From googling I might have to build a custom cell and put the image in there and then load that custom cell? I’ve not done anything like that before and it seems a bit annoying just to load one image. Is there an alternative?
To put in context, I have 3 sections in the tableview top section will be the image, and the other two are arrays loaded from XML files. If I do a custom cell I have to do a seperate xml call to get the image url before it goes through so I’d really like to avoid that if possible?
Really looking for any pointers you can offer. Thanks a lot
Tom
Edit: cellforrowindexpath as requsted:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section == 0)
cell.imageView.image = [UIImage imageNamed:@"prem.jpg"];
if(indexPath.section == 1)
cell.textLabel.text = [arryTableData objectAtIndex:indexPath.row];
else if(indexPath.section == 2)
cell.textLabel.text = [arryTableActions objectAtIndex:indexPath.row];
return cell;
}
There is no need to create a custom cell subclass. I am assuming you have a single cell in section 0 and a variable number of cells in sections 1 and 2.
You should be using a different cell reuse identifier for your cell in section 0 as it contains an image view and the others don’t – this will show up in your later sections when the cells are recycled otherwise.
I’d try something like this:
Make sure you are adding the image to the newly created image view and not cell.imageView as the latter is a read-only property which is over to the left side, I’m not sure you can resize it.
You will also need to set the height for your cell, as it is taller than the standard. This will be in the
tableView:heightForRowAtIndexPath:delegate method.