如下图所示,我在UITableViewCell中使用UIButton,可以选择此按钮,黄金星和未选中的灰色星。当选择UITableViewCell时,UIButton会被覆盖
的问题是,被选择的小区不断时,无论按钮被选中或未被它会变成灰色(这灰色颜色比中的未选定模式的灰度颜色不同星)。我一直在试图弄清楚为什么会发生这种情况,但没有运气。
这里是细胞的实施,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom]retain];
//set the background of the cells
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cellBackground.png"]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellselected2.png"]];
// set the button content
[button setImage:[UIImage imageNamed:@"star.png" ] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"starSelected.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(selectedButton:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(280, 10, 24, 24)];
[cell addSubview:button];
return cell;
}
还当我点击该按钮时,电池选择按钮将完全消失!
谢谢,
接受你自己的问题的答案没关系。 – 2012-01-22 05:52:18