繁体   English   中英

如何从Firebase将所有数据检索到Swift中的一个表行中?

[英]How to retrieve all data from Firebase into one table row in Swift?

我有3个文本字段,其中用户提供3个输入。

我希望这3个输入全部显示在同一行中,但是现在我的应用程序正在一行中显示每个值。

我的JSON由根BilletSalg组成,它包含具有3个键的ticketsPriceTicketNameName 用户在另一个视图控制器中键入它们的值。

我希望将3个键显示在同一行中,但是现在我得到的是带有price值的行,然后是具有ticketName值的新行,最后是具有Name值的第三行。

这是我的代码:

import UIKit
import Firebase

  class TestTableViewController: UITableViewController {
var files: [FIRDataSnapshot]! = []
func mini() {
    let ref = FIRDatabase.database().reference().child("BilletSalg")
    let usersRef = ref.child("tickets").childByAutoId().observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in

        self.files.append(snapshot)

        print(snapshot)


})
}

let cellNavn = "cellNavn"

  var holes: [FIRDataSnapshot]! = []


let CoursesRef = FIRDatabase.database().reference().child("BilletSalg")





override func viewDidLoad() {
    super.viewDidLoad()

    CoursesRef.observeEventType(.Value, withBlock: { snapshot in




        self.holes = snapshot.childSnapshotForPath("tickets").children.allObjects as! [FIRDataSnapshot]
    self.tableView.reloadData()

    })

    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .Plain, target: self, action: #selector(handleCancel))

    tableView.registerClass(NavnCell.self, forCellReuseIdentifier: cellNavn)




}


func handleCancel() {
    dismissViewControllerAnimated(true, completion: nil)
}

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

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(cellNavn, forIndexPath: indexPath) as! NavnCell



   // I want 3 labels to display the 3 values typed by the user, so in each Row you can view the 3 values

        cell.detailTextLabel?.text = self.holes[indexPath.row].value as? String


 //        cell.textLabel?.text = self.holes[indexPath.row].value as? String
 //
  //        cell.anotherlabel.text? = self.holes[indexPath.row].value as? String


    return cell

    }

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 72
}





}

您应该创建一个新的快捷文件UITableViewCell,并且tableView原型单元必须是该UITableViewCell的子类。 我猜您有一个名为NavnCell的UITableViewCell。 然后,您应该在表视图中将标签添加到原型单元格中(假设它们被命名为firstLabel,secondLabel,thirdLabel),并在UITableViewCell.swift文件中向其添加出口。 然后在你的

tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath)

用作cell.firstLabel.text,cell.secondLabel.text等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM