My-Code oben sollte die ios Liste mit meinem Modell Symptom füllen:Während Zelle wiederverwenden und UISwitch setzen aktiv oder nicht, setzt ios listview aktiv die erste Zeile und zuletzt, was ist falsch?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
UITableViewCell {
tableView.registerNib(UINib(nibName: "SymptomTableCell", bundle: nil),
forCellReuseIdentifier: "cell")
if let cell = tableView.dequeueReusableCellWithIdentifier("cell")
as? SymptomTableCell {
print(indexPath.row)
print(cell)
let symptom = symptoms[indexPath.row]
if Editor.isEditing {
cell.setDatasource(symptom, isSelected:
hasSymptom(symptomsEdit, oid: symptom.oid))
} else {
cell.setDatasource(symptom, isSelected: cell.swItem.on)
}
cell.tag = Helper.random()
cell.backgroundColor = UIColor.clearColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
tableCells.append(cell)
return cell
}
return UITableViewCell()
}
Diese beiden meine Objekte sind die UITableView zu erfüllen Sie können die Bilder sehen das verstehen, befestigt Fehler:
import Foundation
import EVReflection
class Symptom: EVObject {
var oid = ""
var name = ""
}
import UIKit
class SymptomTableCell: UITableViewCell {
var symptom: Symptom?
@IBOutlet weak var swItem: UISwitch!
@IBOutlet weak var lblItem: UILabel!
func setDatasource(symptom: Symptom, isSelected: Bool) {
self.symptom = symptom
lblItem.text = symptom.name
swItem.on = isSelected
}
}
1) Rufen Sie nicht 'registerNib' in' cellForRowAtIndexPath'. Mach es einmal in 'viewDidLoad'. 2) Verwenden Sie 'dequeueReusableCellWithIdentifier' nicht. Verwenden Sie 'dequeueReusableCellWithIdentifier: forIndexPath:'. Es kann keine "Null" -Zelle zurückgeben. – rmaddy
Wahrscheinlich liegt es daran, dass Sie registerNib innerhalb von cellForRowAtIndexPath aufrufen –