[source code] iOS Development with Swift Tutorial - 9 - Button Clicking Example

+1 Bucky Roberts · January 25, 2015
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var buckysLabel: UILabel!
    
    //sender is the object that called this method (button)
    @IBAction func buttonPressed(sender: UIButton) {
        let title = sender.titleForState(.Normal)!
        buckysLabel.text = "You clicked the \(title) button"
    }

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Parth Shrivastava · January 25, 2015
I am facing this error. Also I wont able to go operate the app in the simulator.
0 Christopher Davis · February 28, 2015
That helped get passed that and open up the app so thank you but now I have a new problem which I'm not sure what the debugger is trying to tell me since it is a little new.

When I click on the bacon line to change text I keep getting this error

Thread 1 : EXC BAD INSTRUCTIONS 

and in the debugger I get this

fatal error: unexpectedly found nil while unwrapping an Optional value


        
0 Steve Laguna · March 1, 2015
you might have made to many links to the buttons. click on the button then click on the connection inspector on the top right hand corner. check if there are multiple outlet collection. 
  • 1

iOS Development / Swift

107,246 followers
About

This forum is for questions, comments, and general discussion about iOS Development and Swift.

Links
Moderators
Bucky Roberts Administrator