Strange Placement of Image in TableView

Discussion in 'iOS Programming' started by Wellington2k, Jan 24, 2012.

  1. Wellington2k macrumors regular

    Joined:
    Jun 4, 2011
    #1
    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!
     
  2. jonnymo5 macrumors 6502

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #2
    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?
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Wellington, you stated what you're trying to achieve but haven't described what's not working as expected.
     
  4. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #4
    I got it!

    Thanks, jonnymo5!

    I don't know why I didn't think about that. :eek:
     

Share This Page