【发布时间】: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