iOS Eureka创建后更改部分标题

时间:2016-10-31 18:06:15

标签: ios swift eureka-forms

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

我有类似的东西:

viewDidLoad()

中的

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)
    }
}
viewDidAppear()

中的

$("#words").hide()

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

1 个答案:

答案 0 :(得分: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.
    }


}

我希望这能帮到你,最好的问候