Beginning Programming with iOS 11, Swift 4, and Xcode 9 - Buttons and Actions - raywenderlich.com

preview_player
Показать описание
Learn how to add a button to the app and connect it to some Swift 4 code that prints a message to the console.

View playlist:

---

We are also focused on developing a strong community. Our goal is to help each other reach our dreams through friendship and cooperation. As you can see below, a bunch of us have joined forces to make this happen: authors, editors, subject matter experts, app reviewers, and most importantly our amazing readers!

---

When you tap a button, or select a button that has focus, the button performs any actions attached to it. You communicate the purpose of a button using a text label, an image, or both. The appearance of buttons is configurable, so you can tint buttons or format titles to match the design of your app. You can add buttons to your interface programmatically or using Interface Builder.

Target-action is a design pattern in which an object holds the information necessary to send a message to another object when an event occurs. The stored information consists of two items of data: an action selector, which identifies the method to be invoked, and a target, which is the object to receive the message. The message sent when the event occurs is called an action message. Although the target can be any object, even a framework object, it is typically a custom controller that handles the action message in an application-specific way.

The event triggering an action message can be anything, just as the object sending the message can be any object. For example, a gesture-recognizer object might send an action message to another object when it recognizes its gesture. However, the target-action paradigm is most commonly found with controls such as buttons and sliders. When a user manipulates a control object, it sends the message to the specified object. The control object is an instance of a subclass of UIControl (iOS) or NSControl (OS X). Both action selector and target object are properties of a control object or, in the AppKit framework, properties of the control’s cell object.
Рекомендации по теме