是否可以在tableviewcell中更改uitableviewcellaccessory图像?
答案 0 :(得分:2)
- (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];
}
答案 1 :(得分:1)
是,在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
方法中使用此代码
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;