我遇到与this非常相似的问题。
我在故事板中有一个自定义的UITableViewCell原型,其中包含图像视图和标签。我控制拖动出口并设置我的单元标识符名称“BasicCell”。
class newsTableViewCell: UITableViewCell {
@IBOutlet weak var label: UILabel!
@IBOutlet weak var image1: UIImageView!
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: UITableViewCellStyle.Value1, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func configure(text: String, image2: UIImage){
label.text = text
image1.image = image2
}
}
在我简化的UITableViewController中我有:
class mainlistTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(newsTableViewCell.classForCoder(), forCellReuseIdentifier: "BasicCell")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "BasicCell";
let myCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! newsTableViewCell
myCell.configure("12345", image2: UIImage(imageLiteral: "Default.png"))
return myCell
}
}
当我这样运行时,我在func configure
收到错误,即IBOutlet标签不存在。
当我删除该行:self.tableView.registerClass(newsTableViewCell.classForCoder(), forCellReuseIdentifier: "BasicCell")
时,程序在行let myCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! newsTableViewCell
处崩溃并输出以下内容:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView _isResizable]: unrecognized selector sent to instance 0x7f9dbb61b360'
关于可能是什么原因的任何想法?
答案 0 :(得分:1)
选择UITableViewCell
原型,在属性检查器集" BasicCell"作为标识符。
右键单击Cell中的UIImageView和UILabel,确保没有未连接或旧连接。
删除self.tableView.registerClass(..)
应该没问题。