IBOutlet是零,但它连接在故事板(Swift 2)

问题描述:

我试图在UITableView的单元格中显示一些内容。该方案确实达到了cellForRowAtIndexPath:IBOutlet是零,但它连接在故事板(Swift 2)

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 
} 

我已经正确连接网点enter image description here

如果我设置断点,细胞似乎是EventTableViewCell,但两者cellLabeltextField是零: enter image description here

我的表格视图连接如下所示:

对于这里的eventCell

enter image description here

连接检查: enter image description here

我也取得了查看内容的背景颜色为蓝色,但似乎我没有看到我的手机全部内容视图。

我的自定义单元格类看起来是这样的: enter image description here

+0

您是否在TableView中使用autoLayout?如果是,那么请检查您的意见的自动布局约束。还请检查您是否具有tableview的映射委托和数据源到Storyboard中的相应ViewController。 –

+0

已检查:不使用自动布局约束,并且委托和数据源已连接 –

+0

您可以显示您的自定义单元格吗? –

检查您是否具有对IB你的正确的标识符。让cell ...返回零,这似乎是你的问题。

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

它有正确的标识符,我首先检查了它。 –

+0

cell不是nil,cell是EventTableViewCell类型的对象,奇怪的是默认单元格文本的第一行工作:cell.textLabel?.text = ...但是我的cell.cellLable?.text = ... does不。 –

+0

您可以通过突出显示eventCell并显示Connections Inspector来显示所有单元出口的连接吗? –

cell.textLabel可以工作,因为您继承了UITabelViewCell类。你得到一个UITabelViewCell作为参考 - 这是被授予的。

在范围内创建对您的标签的强烈参考。 放置一个断点并验证您实际获得的细胞。 (的确是您的正确的子类或通用的。)

如果单元格对象是正确的,但没有获得标签,它必须与插座相关。 在Swift中的某些情况下,我需要将UIElement的OUTLET从弱变为强壮。

如果是,则只有标签的属性仍然是原因。给标签一个背景颜色。它的布局实际上是可见的? (例如:hidden = NO,alpha = 1,frame/constrains使其可见等等。)