2

I am using Eureka Forms in my Swift 4 app and I do not use storyboards. Setting up the form programmatically is working fine, however I am using a popoverPresentationController to display a UIViewController with a NavBar in and using the form as a FormViewController means the top of the form is hidden underneath the NavBar.

I'd like make the Class as UIViewController and then add the Eureka form as a Subview so I can using constraints as normal. I understand this is achieved by using UITableView, so I have set it up as follows but I'm not sure how to wire in the Eureka Form and I can't find anything in the documentation about it.

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

Any pointers?

Tony Law
  • 293
  • 2
  • 13
  • you can add it as subview : https://stackoverflow.com/questions/27276561/adding-a-view-controller-as-a-subview-in-another-view-controller – Ammar Dec 22 '18 at 07:15

0 Answers0