Metin Atalay Metin Atalay - 5 months ago 37
Swift Question

Swift UIButton text does not change

I have one UIButton in a UIView and I change the its title. But when I the get the button title it is giving me the old title and not the changed one. However when I call it from somewhere when the method is finished its true


enter image description here


Wrapping your if statements in a performWithoutAnimation block will prevent any delays in updates to the titleLabel.

UIView.performWithoutAnimation {
    if btnOne.titleLabel?.text == "qq" {
        btnOne.setTitle("metin", forState: .Normal)
        var a = btnOne.titleLabel?.text // "metin"
        mergeString += sender.titleLabel!.text!