Bird
0
0

Which UITableViewDelegate method should you implement to return a custom UIView as the header for a specific section?

easy📝 Conceptual Q2 of 15
iOS Swift - Lists and Data Display
Which UITableViewDelegate method should you implement to return a custom UIView as the header for a specific section?
AtableView(_:heightForHeaderInSection:)
BtableView(_:titleForHeaderInSection:)
CtableView(_:viewForHeaderInSection:)
DtableView(_:willDisplayHeaderView:forSection:)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method for custom header views

    The UITableViewDelegate method tableView(_:viewForHeaderInSection:) allows you to provide a custom UIView for the header.
  2. Step 2: Understand other methods

    titleForHeaderInSection provides a simple text title, heightForHeaderInSection sets the height, and willDisplayHeaderView is for customization before display but does not provide the view.
  3. Final Answer:

    tableView(_:viewForHeaderInSection:) -> Option C
  4. Quick Check:

    Custom header views require viewForHeaderInSection [OK]
Quick Trick: Custom header views use viewForHeaderInSection method [OK]
Common Mistakes:
  • Confusing titleForHeaderInSection with viewForHeaderInSection
  • Using heightForHeaderInSection to provide the view
  • Assuming willDisplayHeaderView returns the view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes