【发布时间】:2016-10-05 18:02:41
【问题描述】:
现在,在我的用户输入 3 个文本字段后,我得到 3 个单元格,每个单元格都包含用户输入的值之一。
我怎样才能让这 3 个值都显示在同一个单元格中?
在我的NavnCell 文件中,我创建了多个标签,但它们的行为仍然相同。似乎我的应用程序获取数组中的第一个值并显示它,然后创建另一个单元格来显示第二个值。
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]
var newItems = [FIRDataSnapshot]()
for item in snapshot.childSnapshotForPath("tickets").children {
newItems.append(item as! FIRDataSnapshot)
}
//replace the old array
self.holes = newItems
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.timeLabel.text = self.holes[indexPath.row].value as? String
cell.detailTextLabel?.text = self.holes[indexPath.item].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
}
}
【问题讨论】:
-
"cell.timeLabel.text = self.holes[indexPath.row].value as?String" — 但这只是一个标签 (cell.timeLabel)。
标签: ios swift uitableview firebase firebase-realtime-database