There sure are a lot of UIButton questions here, and I was hoping to find the answer to this, but nothing quite like this particular issue.
I have a few buttons, and I can call button.highlighted = YES;
for any button when the program runs and it shows up highlighted.
I thought I could then use this same technique to set a button's highlight state to YES after it pressed, and then set it to NO after another button is pressed. This way, the current selection remains highlighted.
For example:
-(IBAction) buttonPressed:(UIButton *)button
{
if (button.tag==1)
{
self.button1.highlighted=YES;
self.button2.highlighted=NO;
// do other program stuff here
}
if (button.tag==2)
{
self.button2.highlighted=YES;
self.button1.highlighted=NO开发者_如何学编程;
// do other program stuff here
}
}
Even though the highlights work fine if I place the highlighted = YES;
code inside viewDidLoad. But the above code does not work. The highlight doesn't stick. The buttons works, and does the other stuff it needs to do, but the highlights fail to stick.
I would think this should be pretty basic. Is iOS somehow automatically setting all button highlights to NO on its own after any button operation?
May be you should use other means to present the highlight status, because of the statement from UIControl
's documentation:
By default, a control is not highlighted. UIControl automatically sets and clears this state automatically when a touch enters and exits during tracking and when there is a touch up.
You might try using the 'selected' property instead of the 'highlighted' property.
精彩评论