2

我在 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() {
            $0.title = item.description 
        }
        section.append(row)
    }
}

问题是我需要更改部分标题。

4

1 回答 1

4

我一直在处理你的问题,这是我的结果,首先你需要确保你的部分有你以后需要的标签,所以你需要使用这个代码而不是你的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.
    }


}

我希望这对你有帮助,最好的问候

于 2016-11-05T21:27:45.760 回答