Keeping a UIButton selected after a touch

后端 未结 9 1460
后悔当初
后悔当初 2020-11-27 11:41

After my user clicks a button, I\'d like that button to stay pushed during the time that I perform a network operation. When the network operation is complete, I want the bu

9条回答
  •  旧时难觅i
    2020-11-27 12:14

    I had a similar problem where I wanted a button to keep it's highlight after click. The problem is if you try to use setHighlighted:YES inside of you click action it will reset right after you click action, - (IBAction)checkInButtonPushed

    I solved this by using a NSTimer like this

    NSTimer *timer;
    timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
                                             target: self
                                           selector: @selector(selectCurrentIndex)
                                           userInfo: nil
                                            repeats: NO];
    

    and then call setHighlighted:YES from my selectCurrentIndex method. I use regular UIButtonTypeRoundedRect buttons.

提交回复
热议问题