iOS Eureka 创建后更改节标题

标签 ios swift eureka-forms

我正在 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)
    }
}

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

最佳答案

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

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

稍后您可以获取您的部分并更改标题,但如果您不调用 界面中的 section.reload() 永远不会更新,因此请在 section.header?.title = "Contacts: 下面添加 section.reload()\(contacts.count) 已选择”

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


}

希望这对您有帮助,最诚挚的问候

关于iOS Eureka 创建后更改节标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40347941/

相关文章:

ios - 如何获取Firebase云存储中存储的项目的总大小?

iOS和libxml编译警告问题

ios - 在 UILabel 中拟合文本 - Swift

ios - Swift 中的以下 for 循环语法有什么问题?

swift - 如何在两个对象之间创建共享部分

ios - Eureka MultipleSelectorRow

swift - Eureka 表单,TextAreaRow 滚动到底部

swift - Eureka swift : Dismiss Controller for MultipleSelectorRow

ios - 为什么 iOS 9 方法在 iOS 8.4 上仍然有效?

ios - 使用在 UIImageView 上设置的启动图像