【问题标题】:Model for header view标题视图模型
【发布时间】:2020-09-12 04:36:29
【问题描述】:

表格中有 5 个部分。除了第一个和第二个部分之外的所有部分都有一个视图标题。这个视图是使用 xib 制作的。它有一个标签和一个按钮。在每个部分中,此标签和按钮都会更改文本。 我怎样才能实现这个?。我在一个单独的文件中设置了这个快捷方式和按钮的文本。但是我不明白如何在每个部分中显示相应的文本。

 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"
    }
  }
}

【问题讨论】:

    标签: ios swift uitableview header switch-statement


    【解决方案1】:

    您可以为此使用viewForHeaderInSectiondelegate 方法:

    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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      相关资源
      最近更新 更多