views:

199

answers:

2

I want to add an image using the cell.imageView setImage: method. However, depending on field from an array (in the form of an NSString and called using [dog types]) I need the image at the left-hand side of the cell to change to an image which reflects the type of dog.

How do I go about doing this? Thanks.

A: 

Hi, Graeme

I think you can deffinatly can do wht you want to do.

By chacking condition in cellForRowAtIndexPath method :

if(indexPath.row == 0)  // for first cell of tableView

if(indexPath.row == 1)   // for second cell of tableView

hope you can understand...

even if any problem leave a comment...and mark as correct if you got resolved...

yakub_moriss
+1  A: 

As you know for fill the cells contents you have to use the delegate method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

so, you have to put your IF inside this method and use indexPath.row to understand witch row you are drawing. Here a simple example:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
    }
    UIImage *a,*b; //Remeber to init with your images:)
    if(indexPath.row == 1)
    {
        [cell.imageView setImage:a];
    }
    else
    {
        [cell.imageView setImage:b];
    }
    return cell;
}

I hope it's what you was looking for :)

Cesar
could you mark the answer as resolved ? thx :)
Cesar
Hi, it doesn't actually solve my problem though :) What I need to do is use an IF statement, but display an image if it matches [dog types]. For example, the information is downloaded from a server, and is parsed etc. into the [dog types]. What i need then is IF dog type = collie then display collie.png kind of thing!
Graeme