Iphone 更改UITableViewCell附件图像

Iphone 更改UITableViewCell附件图像,iphone,Iphone,是否可以更改tableviewcell中的UITableViewCell附件图像???确实可以。只需替换整个accessoryView - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath // setup cell UIImageView *aView = [[[UIImageView alloc] initWithImage:

是否可以更改tableviewcell中的UITableViewCell附件图像???

确实可以。只需替换整个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;
}

编辑:如果你想使用你的配件像一个披露按钮,有一点更必要

- (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];
}

,在-
(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
方法中使用此代码

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;