I have a screen with a UIImage and a UIButton on it. I wrote code so that when the button is clicked the image changes and it worked. Then I wanted to add code to make the title of the button as well. After I added that code the program crashes with a sigabrt error. I checked the connections and everything look fine. How would I change the text/title of a button without having it crash.
class MapViewController: UIViewController {
@IBOutlet weak var mapButton: UIButton!
@IBOutlet weak var mapImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
//mapButton.setTitle("test", for: .normal)
// Do any additional setup after loading the view.
}
@IBAction func mapButtonTapped(_ sender: UIButton) {
if x == true
{
mapImage.image = #imageLiteral(resourceName: "map")
x = false
mapButton.setTitle("1st Floor Map", for: .normal)
}
else
{
mapImage.image = #imageLiteral(resourceName: "School Map 2015-2016-2")
mapButton.setTitle("2nd Floor Map", for: .normal)
x = true
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var x:Bool = true;