Swift: los IBoutlets son nulos en la celda personalizada
No puedo entender por qué esta celda personalizada no se emite.
Tengo una celda personalizada configurada en un guión gráfico (sin plumín). Tengo un campo de texto y 2 etiquetas que son nulas cuando intento acceder a ellas en la clase de celda personalizada. Estoy casi seguro de que tengo todo conectado correctamente, pero aún así me estoy volviendo nulo.
Seleccioné la celda de mi tabla en el guión gráfico y configuré Clase personalizada enTimesheetTableViewCell
También controlé que hice clic en la tabla y configuré el origen de datos y el delegado para que seaTimesheetViewController
Mi clase de celda personalizada:
import UIKit
class TimesheetTableViewCell: UITableViewCell {
@IBOutlet var duration: UITextField!
@IBOutlet var taskName: UILabel!
@IBOutlet var taskNotes: UILabel!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init?(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
println("Cell's initialised")// I see this
println(reuseIdentifier)// prints TimesheetCell
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
func setCell(duration: String, taskName: String, taskNotes: String){
println("setCell called")
self.duration?.text = duration
self.taskName?.text = taskName
self.taskNotes?.text = taskNotes
}
Mi controlador:
class TimesheetViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
@IBOutlet var timesheetTable: UITableView!
var items = ["Item 1", "Item2", "Item3", "Item4"]
override func viewDidLoad() {
super.viewDidLoad()
self.timesheetTable.registerClass(TimesheetTableViewCell.self, forCellReuseIdentifier: "TimesheetCell")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TimesheetCell", forIndexPath: indexPath) as TimesheetTableViewCell
println(items[indexPath.row]) // prints corresponding item
println(cell.duration?.text) // prints nil
cell.setCell(items[indexPath.row], taskName: items[indexPath.row], taskNotes: items[indexPath.row])
return cell
}