【发布时间】:2015-04-28 17:39:18
【问题描述】:
我有这个问题,无论我在自定义 uitabelviewcell 中放入什么变量“var”,它都会返回 nil 虽然 IBoulets 工作得很好
tableviewcell.swift
import Foundation
import UIKit
class tableViewCell: UITableViewCell {
@IBOutlet weak var tableViewLabelDate: UILabel!
@IBOutlet weak var tableViewLabelDisplayName: UILabel!
@IBOutlet weak var tableViewLabelSubject: UILabel!
@IBOutlet weak var tableViewTextViewInfo: UITextView!
var messageRenderingOperation: MCOIMAPMessageRenderingOperation!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
tableview.swift
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell2: tableViewCell = tableView.dequeueReusableCellWithIdentifier(reuseTableViewCellIdentifier, forIndexPath: indexPath) as tableViewCell
cell2.tag = 0
let message: MCOIMAPMessage = mailbox?.messages[indexPath.row] as MCOIMAPMessage!
let uidKey = message.uid
cell2.tableViewLabelDisplayName?.text = mailbox?.messages[indexPath.row].header.from.displayName
cell2.tableViewLabelSubject?.text = mailbox?.messages[indexPath.row].header.subject
println("Got the subject line: \(mailbox?.messages[indexPath.row].header.subject)")
cell2.messageRenderingOperation = self.imapSession.plainTextBodyRenderingOperationWithMessage(message, folder: "INBOX", stripWhitespace: false)
cell2.messageRenderingOperation?.start({ (plaintext: String!, error: NSError!) -> Void in // Crash at this line
if error != nil{
println("ERROR at messageRenderingOperation\(error)")
}else {
cell2.tableViewTextViewInfo.text = plaintext
cell2.messageRenderingOperation = nil
}
})
return cell2
}
它在这一行崩溃
cell2.messageRenderingOperation?.start({ (plaintext: String!, error: NSError!) -> Void in // Crash at this line
更新
我也试过这个
class tableviewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
var messageRenderingOperation: MCOIMAPMessageRenderingOperation?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
self.messageRenderingOperation = imapSession.plainTextBodyRenderingOperationWithMessage(message, folder: "INBOX")
self.messageRenderingOperation.start({ (plaintext: String!, error: NSError!) -> Void in
if error != nil{
println("ERROR at messageRenderingOperation\(error)")
}else {
cell2.tableViewTextViewInfo.text = plaintext
cell2.messageRenderingOperation = nil
}
})
}
}
更新 2
如果我现在使用
var messageRenderingOperation = MCOIMAPMessageRenderingOperation()
那么它不是零,但仍然崩溃。我认为这是“插件”的问题?
【问题讨论】:
-
你试过用 Obj-C 写代码吗?
-
我尽力从 mailcore2 应用程序中的示例中复制代码,结果相同...我不知道为什么它不起作用
标签: uitableview swift tableviewcell mailcore2 mailcore