gpt4 book ai didi

ios - 我怎样才能将所有数据放在一个表中,而不是拆分到多个表中?

转载 作者:行者123 更新时间:2023-11-28 06:32:45 27 4
gpt4 key购买 nike

现在,在我的用户输入 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
}





}

最佳答案

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

我想这里你想要像 holes.count/3 这样的东西,因为你想在一个单元格中显示三个值,所以你的行数应该像 holes div 3,对吧?

在你的 cellForRowAtIndexPath 中它应该是这样的:

let newIndex = indexPath.row * 3
cell.timeLabel.text = self.holes[newIndex].value as? String
cell.timeLabel2.text = self.holes[newIndex + 1].value as? String //next value
cell.timeLabel3.text = self.holes[newIndex + 2].value as? String//another next value

但老实说,从一开始就以正确的方式准备数据对您来说会简单得多。类似于 newHoles,其中 newHole 由 self.hole1、self.hole2 和 self.hole3 组成。

关于ios - 我怎样才能将所有数据放在一个表中,而不是拆分到多个表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39880833/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com