// Variable and ViewDidLoad
var auxRow = 0
var auxSection = 0
override func viewDidLoad() {
super.viewDidLoad()
}
// Anzahl der Abschnitte, nur einen AbschnittWarum wird der numberOfRowsInSection für nur einen Abschnitt mehrmals aufgerufen?
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
auxSection += 1
print("times section: ", auxSection)
return 1
}
// Anzahl der Zeilen
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
auxRow += 1
print("times row: ", auxRow)
return 2
}
// Tableview Konfigurieren Sie die Zelle
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let textCellIdentifier = "cellText"
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath)
let variable : String = indexPath.row.description
cell.textLabel?.text = variable
return cell
}
Ausgang:
times section: 1
times row: 1
times section: 2
times row: 2
times section: 3
times row: 3
times section: 4
times row: 4
Die Methode numberOfRowsInSection
wird 4 Mal aufgerufen. Warum passiert das?
Ich verstehe nicht, warum geben Sie 4 mal in der Methode numberOfRowsInSection. Ich habe nur einen Abschnitt – PedroMeira
@Lamar: OP fragt, warum die Methode numberOfRowsInSection 4 mal ausgeführt wird, weil er nur 1 Abschnitt hat (nicht 4 Abschnitt, also theoretisch sollte diese Methode nur einmal ausgeführt werden) –
numberOfRowsInSection -Methode wird 4 mal ausgeführt, weil? Was ist der Grund? – PedroMeira