我一直在处理你的问题,这是我的结果,首先你需要确保你的部分有你以后需要的标签,所以你需要使用这个代码而不是你的viewDidLoad()
代码
form +++ Section("contacts-selected"){section in
section.tag = "contacts-selected"
}
稍后您可以获取您的部分并更改标题,但是如果您不调用
section.reload()
界面将永远不会更新,因此请在section.reload()
下面添加您的section.header?.title = "Contacts: \(contacts.count) selected"
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() {
$0.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(){
$0.title = "Phone Row"
$0.placeholder = "And numbers here"
}
+++ Section("Section2")
<<< DateRow(){
$0.title = "Date Row"
$0.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.
}
}
我希望这对你有帮助,最好的问候