【问题标题】:I am facing this error "exc_bad_instruction (code=exc_i386_invop subcode=0x0)"我正面临这个错误“exc_bad_instruction (code=exc_i386_invop subcode=0x0)”
【发布时间】:2018-08-30 12:00:18
【问题描述】:

我正在运行以下代码并在 swift 中遇到错误。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     let cell = Collection_View.dequeueReusableCell(withReuseIdentifier: "list", for: indexPath) as! List_CollectionViewCell
     cell.list_name.text = items[indexPath.row]
     **cell.created_date.text = c_date[indexPath.row]**
     return cell
}

为什么 xcode 会在这一行产生这个错误?

【问题讨论】:

  • 索引超出范围或展开 nil 可选。
  • c_date 中有什么内容?还有created_date的类型是什么?
  • ->created_date 是 UILabel,我将更新我的 UILabel 的文本,它是 CollectionViewCell 的一个元素... ->c_date 是一个字符串数组,我通过它更新我的 UILabel
  • c_date 与项目 arr 的计数相同??并且标签连接正确
  • 是的...当项目被创建时,它的日期会自动生成,这就是为什么两者的计数相同

标签: ios swift xcode collectionview exc-bad-instruction


【解决方案1】:

当强制展开失败时会出现此错误。确保您的故事板中原型的类在 Identity Inspector 中设置为 List_CollectionViewCell

并且它的标识符在属性检查器中是"list"

【讨论】:

    猜你喜欢
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多