Reputation: 53
I'm trying to realize tik tak toe game. So, I have 9 buttons and every time I'm pressing on them they install their text label as "X" or "O"
sender.setTitle("X", for: .normal)
// or
sender.setTitle("O", for: .normal)
But then , when game is finished , I want to delete all text labels and facing a problem - I can't remove text labels. I've tried several variants and still can't understand problem. I tried :
button.setTitle(nil, for: .normal)
button.setTitle("", for: .normal)
button.titleLabel?.text = ""
button.titleLabel?.text = nil
It's not working. Even if I don't see text at this buttons after my "failed reset", text is still set. Even when I'm doing all variants to delete text and then calling
button.titleLabel?.text
Im getting not empty line or nil, Im getting "X"!!! (if there was "x" text before)
Upvotes: 1
Views: 5117
Reputation: 14397
i checked it ... these all lines work .. problem is with your connection
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
self.button.setTitle("", for: .normal)
//self.button.backgroundColor = .red
}
super.viewDidLoad()
// Do any additional setup after loading the view.
}
Upvotes: 2