Wie verwende ich die heightForRowAtIndexPath-Methode?IOS

Programmierung für iOS
Anonymous
 Wie verwende ich die heightForRowAtIndexPath-Methode?

Post by Anonymous »

Ich versuche, die Methode heightForRowAtIndexPath in meinem UITableViewController zu verwenden. Aber wenn ich versuche, die Methode zu überschreiben, heißt es, dass sie keine Methoden aus ihrer Oberklasse überschreibt.

Googeln hat mich zu Protokollen geführt, die möglicherweise Teil des Puzzles zu sein scheinen, aber ich versuche immer noch zu verstehen, wie man ein Protokoll verwendet, um diese Methode zu verwenden.

Jede Hilfe wäre sehr dankbar. Hier ist der Code: (die Problemmethode steht ganz unten)

Code: Select all

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
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post