Recall & Review
beginner
What is the purpose of a UIButton in iOS development?
A UIButton is a user interface element that users can tap to trigger an action or event in the app.
Click to reveal answer
beginner
How do you connect a UIButton to an action in Swift code?
You connect a UIButton to an action by creating an @IBAction function and linking it to the button's Touch Up Inside event in Interface Builder or programmatically.
Click to reveal answer
beginner
What does the @IBAction keyword indicate in Swift?
@IBAction marks a method that can be connected to a user interface element event, like a button tap, allowing the method to be called when the event occurs.
Click to reveal answer
intermediate
How can you add a button action programmatically in Swift?
You create a UIButton instance, then use addTarget(_:action:for:) to specify the method to call when the button is tapped.
Click to reveal answer
intermediate
Why is it important to specify the event type like .touchUpInside when adding a button action?
Specifying the event type ensures the action triggers only on the intended user interaction, such as when the user lifts their finger inside the button area, preventing accidental triggers.
Click to reveal answer
Which keyword is used to mark a method as an action for a UIButton in Swift?
✗ Incorrect
@IBAction marks a method that can be connected to UI events like button taps.
What event type is commonly used to trigger a button action when the user taps it?
✗ Incorrect
.touchUpInside triggers the action when the user lifts their finger inside the button.
How do you connect a UIButton to an action in Interface Builder?
✗ Incorrect
You drag from the button to the @IBAction method to connect the action.
Which method adds an action to a UIButton programmatically?
✗ Incorrect
addTarget(_:action:for:) is used to add an action to a UIButton programmatically.
What happens if you do not specify the event type when adding a button action?
✗ Incorrect
If no event is specified, the action may trigger on multiple events, causing unexpected behavior.
Explain how to create a button and handle its tap action in Swift using Interface Builder.
Think about the steps from dragging a button to writing the action method.
You got /4 concepts.
Describe how to add a button and its action programmatically in Swift code.
Focus on creating the button and linking the tap event in code.
You got /4 concepts.