我正嘗試在我的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中將行高設置爲自定義,並將高度設置爲不起作用。 –