Hassam
Hassam

Reputation: 253

How to change the UITableViewCell image on the left on the UIBarButtonItem?

I am a newbie to iPhone programming. I am stuck in a situation. I need to change the UITableViewCell image (on the left side) through calling an action from UIBarButtonItem fromt he UIToolBar. I have searched through internet, but can't find any appropriate solution.

Any Help regarding this would be appreciated.

Upvotes: 0

Views: 545

Answers (2)

rayyildiz
rayyildiz

Reputation: 338

Here is a sample code for customizing cell imageView.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        
    static NSString *CellIdentifier = @"MyTableViewCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                          reuseIdentifier:CellIdentifier];

      [cell.imageView setBounds:CGRectMake(0, 0, 30, 30)];
      [cell.imageView setClipsToBounds:YES];
      [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)];

      [cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
    }

    // customize cell
    [cell.imageView setImage:**your_image**];


    return cell;
}

Upvotes: 2

Kasper Munck
Kasper Munck

Reputation: 4191

With the [tableview cellForRowAtIndexPath:] method you can access a cell at a specific row. When you have accessed that you can reach the image by cell.imageView. Have a look at this:

- (IBAction)barbuttonPressed
{
    UITableViewCell *cell = [self.tableView [NSIndexPath indexPathForRow:row inSection:section];
    cell.imageView = ..... 
}

Replace row and section with appropriate.

Upvotes: 0

Related Questions