Bird
0
0

Given this code snippet inside a UITableViewDelegate method, what happens when the user swipes the cell?

medium📝 ui behavior Q13 of 15
iOS Swift - Lists and Data Display
Given this code snippet inside a UITableViewDelegate method, what happens when the user swipes the cell?
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { _, _, completionHandler in
    print("Deleted")
    completionHandler(true)
}
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
return configuration
AA red "Delete" button appears; tapping it prints "Deleted" and closes swipe
BThe cell immediately deletes without user interaction
CNothing happens because completionHandler is not called
DThe swipe gesture is disabled
Step-by-Step Solution
Solution:
  1. Step 1: Analyze swipe action setup

    A destructive style button labeled "Delete" is created with a handler that prints and calls completionHandler(true).
  2. Step 2: Understand user interaction

    Swiping reveals the button; tapping it triggers the handler, printing "Deleted" and ending the swipe.
  3. Final Answer:

    A red "Delete" button appears; tapping it prints "Deleted" and closes swipe -> Option A
  4. Quick Check:

    Swipe button tap triggers handler = A red "Delete" button appears; tapping it prints "Deleted" and closes swipe [OK]
Quick Trick: Completion handler true ends swipe and triggers action [OK]
Common Mistakes:
  • Thinking swipe deletes immediately without tap
  • Forgetting to call completionHandler(true)
  • Assuming swipe gesture disables without code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes