我正在尝试使用UILabels和UIImageViews的出口创建自定义UITableViewCell。但是,每当我尝试设置这些插座的任何值时,都会发生致命错误。我在常规ViewController中有一个UITableView
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: StoreTableCell = tableView.dequeueReusableCellWithIdentifier("cell",
forIndexPath: indexPath) as! StoreTableCell
let currentItem = storeSection[indexPath.row]
cell.ItemName.text = currentItem[0]
cell.ItemDescription.text = currentItem[1]
cell.ItemImage.image = UIImage(contentsOfFile: currentItem[2])
cell.ItemPrice.text = currentItem[3]
return cell
}
我的currentItem数组永远不会为空,并且每个索引总是有一个字符串。
这是我的storeTableCell类:
class StoreTableCell: UITableViewCell{
@IBOutlet var ItemName: UILabel!
@IBOutlet var ItemImage: UIImageView!
@IBOutlet var ItemDescription: UILabel!
@IBOutlet var ItemPrice: UILabel!
required init(coder aDecoder: NSCoder) {
fatalError("NSCoding not supported")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}
每当我尝试设置其中一个出口时,错误总是发生在(cellForRowAtIndexPath)中。值,不管我分配它们的顺序。任何建议,对Swift来说都是新手。
答案 0 :(得分:1)
我打赌你的一个插座设置不正确。很容易弄乱你的代码的插座连接,留下零引用。转到您的故事板并查看视图控制器的顶部,找到一个带方框的黄色圆圈。右键单击它以查看所有商店。你可能会发现一个旧的仍然在那里标有黄色警告三角形。单击它附近的x将其删除。