jojiReptiloid
jojiReptiloid

Reputation: 286

Model for header view

There are 5 sections in the table. In all sections except the first and second there is a view header.This view is made using xib. It has a label and a button. In each section, this label and button changes the text. How can i implement this?.The text for this shortcut and button I set in a separate file. But I don’t understand how to show the corresponding text in each section.

 enum header: Int, CaseIterable {

case oneSection
case twoSection
case thirdSection
case fourthSection
case fifthSection

var title:String {
switch self {
case .oneSection:
return ""
case  .twoSection: 
return ""
case .thirdSection:
return "thirdSection"
case .fourthSection:
return "fourthSection"
case  .fifthSection:
return "fifthSection"
    }
  }
}

Upvotes: 2

Views: 70

Answers (1)

koen
koen

Reputation: 5741

You can use the viewForHeaderInSectiondelegate method for this:

enum header: Int, CaseIterable {
   case oneSection = 0
   case twoSection
   case thirdSection
   case fourthSection
   case fifthSection
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

   let view = // load your view here from the xib

   switch section {
   case .thirdSection:
   view.label = "thirdSection"

   case .fourthSection:
   view.label = "fourthSection"

   case .fifthSection:
   view.label = "fifthSection"

   default:
      break
   }

   return view
}

Upvotes: 2

Related Questions