我在每个单元格中都有一个UITableViewCell
UIButton
。按下按钮时,我将其状态设置为高亮显示,如this回答:
[self performSelector:@selector(doHighlight:) withObject:[cell.subviews objectAtIndex:2] afterDelay:0.0];
然后我这样做:
- (void)doHighlight:(UIButton *)sender {
if (sender.highlighted) {
[sender setHighlighted:NO];
} else {
[sender setHighlighted:YES];
}
}
但按钮不仅没有突出显示,也没有说明我应该能够突出显示它。
关于什么是错的任何想法?
答案 0 :(得分:1)
我最终使用了UIButton
的{{1}}属性。它不需要任何selected
,它可以很好地处理这类事情:
delay
答案 1 :(得分:0)
这是您正在寻找的可能解决方案。我修改了我的答案
UIButton *button=[cell.subviews objectAtIndex:2];
//I am adding these five lines to ensure the different
//states of the button to achieve your highlighted state goal.
UIImage *highlightImage = [UIImage imageNamed:@"highlight.png"];//Also used when button is selected
UIImage *normalImage = [UIImage imageNamed:@"normal.png"];
[button setBackgroundImage:normalImage forState:(UIControlStateHighlighted)];
[button setBackgroundImage:highlightImage forState:(UIControlStateSelected)];
[button setBackgroundImage:normalImage forState:UIControlStateNormal];
[self performSelector:@selector(doHighlight:) withObject:[cell.subviews objectAtIndex:2]];
-(IBAction) doHighlight:(id)sender
{
if ([sender isKindOfClass:[UIButton class]])
{
UIButton *btn=(UIButton*)sender;
if (btn.isSelected) {
[btn setSelected:NO];
}
else
{
[btn setSelected:YES];
}
}
}