首页 > 解决方案 > 如何使用 Eureka 将单元格添加到 UITableViewController?

问题描述

我正在尝试编写一个表格视图应用程序,该应用程序从 Eureka 表单中获取数据,并根据该数据创建单元格。我无法弄清楚如何使用表单中用户提供的数据创建表格视图单元格并插入它。代码如下。

    +++ Section()
        <<< ButtonRow() { row in
            row.title = "Save Entry"
            }.onCellSelection { (cell,row) in
                self.submit()
    }
}

func submit() {
    self.dismiss(animated: true, completion: {
        var entry = Entry(name: self.name, size: self.size, dateComponents: self.date)
    })
}

很难从上到下获取数据。

class SneakerTableViewController: UITableViewController {

var entries = Array<Entry>()

@objc func insert() {
    let insertionIndexPath = NSIndexPath(row: entries.count - 1, section: 0)
    tableView.insertRows(at: [insertionIndexPath as IndexPath], with: .automatic)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return CustomTableViewController.entries.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let customCell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! CustomCell



    let entry = entries.last

    let dateFormatter: DateFormatter = DateFormatter()
    dateFormatter.dateFormat = "MM/dd/yy"

    customCell.nameLabel.text = entry.name
    customCell.sizeLabel.text = String(format: "%.1f", entry.size)
    customCell.dateLabel.text = dateFormatter.string(from: entry.date)

    customCell.customTableViewController = self

    return customCell
}
}

谢谢!非常感谢任何和所有帮助,如果有什么我可以分享或回答以澄清,请告诉我!

标签: iosswifteureka-forms

解决方案


推荐阅读