ios - IBOutlet 为零,但在 Storyboard 中已连接(Swift 2)

标签 ios xcode storyboard swift2

我试图在 UITableView 的单元格中显示一些内容。该程序确实到达了 cellForRowAtIndexPath:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell: EventTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("eventCell") as! EventTableViewCell

    let date = self.eventArray[indexPath.row].startTime
    let calendar = NSCalendar.currentCalendar()
    let minutes = calendar.component(NSCalendarUnit.Minute, fromDate: date)
    var minutesString: String
    if (minutes == 0) {
        minutesString = "00"
    } else {
        minutesString = String(calendar.component(NSCalendarUnit.Minute, fromDate: date))
    }
    let hours = calendar.component(NSCalendarUnit.Hour, fromDate: date)
//this next line of code works, i see cell text:
//  cell.textLabel?.text = self.eventArray[indexPath.row].title + " - \(hours):\(minutesString)"

//these lines do not work, see empty cells:
    cell.cellLable?.text = self.eventArray[indexPath.row].title + " - \(hours):\(minutesString)"
    cell.textField?.text = self.eventArray[indexPath.row].notes
    return cell
}

我已正确连接 socket : enter image description here

如果我设置断点,单元格显示为 EventTableViewCell,但 cellLabeltextField 都是 nil: enter image description here

我的 TableView 连接如下所示:

enter image description here

此处 eventCell 的连接检查器: enter image description here

我也将内容 View 的背景颜色设置为蓝色,但似乎我没有在我的单元格中看到整个内容 View 。

我的自定义单元类如下所示: enter image description here

最佳答案

检查您在 IB 中的单元格标识符是否正确。 Let cell... 返回 nil,这似乎是您的问题。

let cell: EventTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("eventCell") as! EventTableViewCell 

关于ios - IBOutlet 为零,但在 Storyboard 中已连接(Swift 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33478194/

相关文章:

swift - 代码 8 : use of unresolved identifier error even though files share same Target Membership

ios - AutoLayout 标签在屏幕右侧被截断

ios - 我想更改 UINavigationBar 的高度并添加标题..为什么这么难?

ios - Cordova iOS 自定义插件 : handle memory warning

ios - Xcode6 ImageView + Assets 目录。图片未显示

ios - 我必须使用自动布局约束以编程方式在一行中添加标签和文本字段,但项目崩溃

ios - UITableView 在嵌入容器内部的 Controller 之间传递数据

iphone - iOS模拟器认为文档目录是/var/root/Documents

ios - 应用传输安全 (ATS) 和本地已安全连接

objective-c - 使用另一个类的方法中的数据更新 View