ios - IBOutlet 为零,但它在 Storyboard 中连接(Swift 2)
<p><p>我试图在 <code>UITableView</code> 的单元格中显示一些内容。该程序确实到达 <code>cellForRowAtIndexPath:</code></p>
<pre><code> override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: EventTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("eventCell") as! EventTableViewCell
let date = self.eventArray.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.title + " - \(hours):\(minutesString)"
//these lines do not work, see empty cells:
cell.cellLable?.text = self.eventArray.title + " - \(hours):\(minutesString)"
cell.textField?.text = self.eventArray.notes
return cell
}
</code></pre>
<p>我已正确连接<strong>网点</strong>:
<a href="/image/vsc4y.png" rel="noreferrer noopener nofollow"><img src="/image/vsc4y.png" alt="enter image description here"/></a> </p>
<p>如果我设置断点,单元格似乎是 <code>EventTableViewCell</code>,但 <code>cellLabel</code> 和 <code>textField</code> 都是 nil:
<a href="/image/JlTnR.png" rel="noreferrer noopener nofollow"><img src="/image/JlTnR.png" alt="enter image description here"/></a> </p>
<p>我的表格 View 连接如下所示:</p>
<p> <a href="/image/NspKP.png" rel="noreferrer noopener nofollow"><img src="/image/NspKP.png" alt="enter image description here"/></a> </p>
<p>这里的 eventCell 连接检查器:
<a href="/image/Uqlpg.png" rel="noreferrer noopener nofollow"><img src="/image/Uqlpg.png" alt="enter image description here"/></a> </p>
<p>我还将内容 View 的背景颜色设为蓝色,但我的单元格中似乎看不到整个内容 View 。</p>
<p>我的自定义单元格类如下所示:
<a href="/image/Ygr6I.png" rel="noreferrer noopener nofollow"><img src="/image/Ygr6I.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>检查您在 IB 中的单元格标识符是否正确。 Let cell... 返回 nil,这似乎是您的问题。</p>
<pre><code>let cell: EventTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("eventCell") as! EventTableViewCell
</code></pre></p>
<p style="font-size: 20px;">关于ios - IBOutlet 为零,但它在 Storyboard 中连接(Swift 2),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33478194/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33478194/
</a>
</p>
页:
[1]