tags:

views:

49

answers:

2

Hi,

is it possible to change the uitableviewcellaccessory image in tableviewcell??

A: 

sure it is. just replace the whole accessoryView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    // setup cell
    UIImageView *aView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]] autorelease];
    cell.accessoryView = aView;
    return cell;
}

EDIT: If you want to use your accessory like a disclosureButton there is a little bit more necessary.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath        
    // setup cell
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 44, 44);
    [button setImage:[UIImage imageNamed:@"SettingsIcon.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(accessoryButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryView = button;
    return cell;
}

- (void)accessoryButton:(UIControl*)button withEvent:(UIEvent *)event {
    UITableView *tv = (UITableView*)[[button superview] superview];
    UITableViewCell *cell = (UITableViewCell*)[button superview];
    NSIndexPath *ip = [tv indexPathForCell:cell];
    [tv.delegate tableView:tv accessoryButtonTappedForRowWithIndexPath:ip];
}
fluchtpunkt
A: 

YES , in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method use this code

UIImage *image = [UIImage imageNamed:@"yourImage.png"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];

button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
Gyani