Keeping a UIButton selected after a touch

后端 未结 9 1440
后悔当初
后悔当初 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条回答
  •  死守一世寂寞
    2020-11-27 12:39

    I have an easier way. Just use "performSelector" with 0 delay to perform [button setHighlighted:YES] . This will perform re-highlighting after the current runloop ends.

    - (IBAction)buttonSelected:(UIButton*)sender {
        NSLog(@"selected %@",sender.titleLabel.text);
        [self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0];
    }
    
    - (void)doHighlight:(UIButton*)b {
        [b setHighlighted:YES];
    }
    

提交回复
热议问题