0
0
iOS Swiftmobile~5 mins

Button and action handling in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@IBOutlet
Bvar
Cfunc
D@IBAction
What event type is commonly used to trigger a button action when the user taps it?
A.valueChanged
B.touchDown
C.touchUpInside
D.editingDidEnd
How do you connect a UIButton to an action in Interface Builder?
ADrag from the button to the @IBAction method
BDrag from the button to the @IBOutlet variable
CWrite code in viewDidLoad
DUse addSubview
Which method adds an action to a UIButton programmatically?
AaddTarget(_:action:for:)
BaddAction(_:for:)
CaddGestureRecognizer(_:)
DaddSubview(_:)
What happens if you do not specify the event type when adding a button action?
AThe action will never be called
BThe action triggers on all events
CThe action triggers only on .touchDown
DThe app crashes
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.