我正尝试在我的UITableViewController
中使用heightForRowAtIndexPath
方法。但是当我尝试重写该方法时,它说它不覆盖它的超类中的任何方法。如何使用heightForRowAtIndexPath方法?
谷歌搜索导致我的协议,这似乎可能是困惑的一部分,但我仍然试图了解如何使用协议来使用此方法。
任何帮助将不胜感激。下面的代码:(这个问题的方法是在最底层)
import UIKit
import Firebase
class FruitsTableViewController: UITableViewController {
let rootRef = FIRDatabase.database().reference()
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 15
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)
let busRef = rootRef.child("buses")
busRef.observeSingleEvent(of: .value, with: {(snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
let bus = snapshots[Int(indexPath.row)].key
let busval = snapshots[Int(indexPath.row)].value as! String
cell.textLabel?.text = "Bus \(bus) ------- \(busval)"
}
})
return cell
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Section \(section)"
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 40.0
}
}
完美的答案,谢谢。在Main.storyboard中将行高设置为自定义,并将高度设置为不起作用。 –