Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wellington2k

macrumors regular
Original poster
Hello.

I have a TableView and I want the same image to be in the whole first section. Then have the whole second section have a different image to the first section.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    cell.textLabel.text = [[arrayarray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor colorWithWhite:100 alpha:.60f];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50,5,20,20)];
    imageView.image = [UIImage imageNamed:[imagesarray objectAtIndex:indexPath.section]];
    [cell addSubview:imageView];
    
    return cell;
}

The image array just has the file names.

Thanks!
 
Try cell.imageView = imageView;

or even cell.imageView.image = [UIImage imageNamed:[imagesarray objectAtIndex:indexPath.section]]

I'm guessing that your array is an array of strings with the image names?
 
Wellington, you stated what you're trying to achieve but haven't described what's not working as expected.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.