如下圖所示,我在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