以编程方式在UITableView中使用Eureka Form?

时间:2017-11-01 13:27:21

标签: ios swift xcode4 eureka-forms

我在Swift 4应用程序中使用Eureka Forms,但我不使用故事板。以编程方式设置表单工作正常,但是我使用popoverPresentationController来显示带有NavBar的UIViewController并将表单用作FormViewController意味着表单的顶部隐藏在NavBar下面。

我喜欢将Class作为UIViewController,然后将Eureka表单添加为Subview,这样我就可以正常使用约束了。我知道这是通过使用UITableView来实现的,所以我将其设置如下,但我不确定如何连接Eureka表单,我在文档中找不到任何关于它的内容。

import UIKit
import Eureka

class TestForm: UIViewController, UITableViewDelegate {


let navBar: UINavigationBar = {
    let nav = UINavigationBar(frame: .zero)
    nav.translatesAutoresizingMaskIntoConstraints = false
    return nav
}()

let formTable: UITableView = {
    let table = UITableView(frame: .zero, style: .grouped)
    table.translatesAutoresizingMaskIntoConstraints = false
    table.backgroundColor = .red
    return table
}()


override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(navBar)
    view.addSubview(formTable)

    formTable.delegate = self

    navBar.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    navBar.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    navBar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
    navBar.heightAnchor.constraint(equalToConstant: 44).isActive = true

    formTable.translatesAutoresizingMaskIntoConstraints = false
    formTable.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    formTable.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    formTable.topAnchor.constraint(equalTo: navBar.bottomAnchor).isActive = true
    formTable.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true

    let navItem = UINavigationItem(title: "Add Event")
    let cancelItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: nil, action: #selector(dismissView))
    navItem.leftBarButtonItem = cancelItem
    navBar.setItems([navItem], animated: false)

    Form +++ Section("First Section")
        <<< TextRow("Section 1 Text"){ row in
            row.title = "Text Row"
            row.placeholder = "Enter text here"
        }
        <<< PhoneRow("Section 1 Phone"){
            $0.title = "Phone Row"
            $0.placeholder = "And numbers here"
        }
        .onCellSelection({ (cell, row) in
            self.saveForm()
        })
}
}

任何指针?

0 个答案:

没有答案