Bird
0
0

Which of the following is the correct way to add a target action for value changes on a UISlider in Swift?

easy📝 Syntax Q3 of 15
iOS Swift - User Input and Forms
Which of the following is the correct way to add a target action for value changes on a UISlider in Swift?
Aslider.addTarget(self, action: #selector(sliderChanged), for: .valueChanged)
Bslider.addAction(#selector(sliderChanged), for: .valueChanged)
Cslider.addTarget(self, action: sliderChanged, for: .valueChanged)
Dslider.addTarget(self, selector: sliderChanged, forControlEvents: .valueChanged)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method signature for adding target-action

    The correct method is addTarget(_:action:for:) where action uses #selector syntax.
  2. Step 2: Match the correct syntax

    slider.addTarget(self, action: #selector(sliderChanged), for: .valueChanged) correctly uses addTarget(self, action: #selector(sliderChanged), for: .valueChanged).
  3. Final Answer:

    slider.addTarget(self, action: #selector(sliderChanged), for: .valueChanged) -> Option A
  4. Quick Check:

    addTarget with #selector and .valueChanged = correct [OK]
Quick Trick: Use #selector for action when adding target to UISlider [OK]
Common Mistakes:
  • Omitting #selector
  • Using addAction instead of addTarget
  • Wrong parameter names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes