Metin Atalay Metin Atalay - 21 days ago 5
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

Thanks,

enter image description here

Answer

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!
    }
    ...
}
Comments