iOS 创建后 Eureka 更改部分 header

iOS Eureka Change section header after creation

我正在 viewDidAppear 方法中以 Eureka 形式重新加载数据:

我有类似的东西:

在 viewDidLoad()

form +++ Section("contacts-selected")

在 viewDidAppear()

if let section = form.sectionBy(tag: "contacts-selected") {
    section.removeAll()
    guard let contacts = dataprovider.getContacts() else{
        return
    }
    \ does not work
    section.header?.title = "Contacts: \(contacts.count) selected" 

    for item in contacts {
        let row = Label() {
            [=13=].title = item.description 
        }
        section.append(row)
    }
}

问题是我需要更改章节标题。

我一直在研究你的问题,这是我的结果,首先你需要确保你的部分有你以后需要的标签,所以你需要使用这个代码而不是你的 viewDidLoad()代码

form +++ Section("contacts-selected"){section in
            section.tag = "contacts-selected"
    }

稍后您可以获取您的部分并更改标题,但如果您不致电 界面中的section.reload()永远不会更新,所以在你的section.header?.title = "Contacts: \(contacts.count) selected"下方添加section.reload()

    if let section = form.sectionBy(tag: "contacts-selected") {
    section.removeAll()
    guard let contacts = dataprovider.getContacts() else{
        return
    }
    \ does not work
    section.header?.title = "Contacts: \(contacts.count) selected" 
    section.reload() //this is the important part to update UI

    for item in contacts {
        let row = Label() {
            [=11=].title = item.description 
        }
        section.append(row)
    }
   }

这是一个小示例代码

//
//  ViewController.swift
//  EurekaExamplesSwift3
//
//  Created by Reinier Melian on 11/5/16.
//  Copyright © 2016 Reinier Melian. All rights reserved.
//

import UIKit
import Eureka

class ViewController: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        form = Section("Section1")
            <<< TextRow(){ row in
                row.title = "Text Row"
                row.placeholder = "Enter text here"
            }.onCellSelection({ (textCell, textRow) in
                if let section = self.form.sectionBy(tag: "contacts-selected") {

                    section.header?.title = "Header Changed"
                    section.reload()

                }
            })
            <<< PhoneRow(){
                [=12=].title = "Phone Row"
                [=12=].placeholder = "And numbers here"
            }
            +++ Section("Section2")
            <<< DateRow(){
                [=12=].title = "Date Row"
                [=12=].value = NSDate(timeIntervalSinceReferenceDate: 0) as Date
        }

        form +++ Section("Contacts"){section in
                section.tag = "contacts-selected"
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

希望对您有所帮助,此致