课程: Xcode 15 Essential Training

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Connecting a button

Connecting a button

- [Instructor] In addition to IBOutlets for variable connections to UI elements, storyboards allow you to use IBActions to trigger methods in your code when UI events occur. These events include button presses, the value of a slider changing, and all kinds of other changes and triggers associated with interactive views. Let's take a look at using an IBAction with this button right here. To create the connection, you do a right-click and drag just like we did with the label, so a right-click and drag from the button into my code. Remember here, I'm creating a method instead of a variable, so I'm going to drag below viewDidLoad. Here, I'm asked to give my method a name. I'll just call this buttonWasPressed, capital W, capital P, all one word, and then hit Return. And there's my method. Notice one big difference between the IBOutlet we created earlier is that connecting a button created an IBAction. Remember, an IBOutlet is a variable that you can modify at runtime or read the values of,…

内容