【发布时间】:2012-01-27 21:10:58
【问题描述】:
我有一个 tableview,我想在它被选中的行的单元格的 contentView 中添加一个 imageview。
这是我当前的代码,当我单击任何单元格时,它只会将 imageView 添加到最后一行而不是我单击的行。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
playIcon = [[UIImageView alloc]initWithFrame:CGRectMake(20, 22, 9, 12)];
UIImage *image = [UIImage imageNamed: @"cell_play.png"];
[playIcon setImage:image];
[cell.contentView addSubview:playIcon];
}
【问题讨论】:
-
您没有显示
cell是如何声明/初始化的。我会 NSLog 它以确保它是有效的......最好使用- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath。
标签: uitableview addsubview didselectrowatindexpath