iOS Strange Placement of Image in TableView

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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!
 

jonnymo5

macrumors 6502
Jan 21, 2008
279
0
Texas
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.