ネストされたコレクションビュー内でテキストラベルを設定できる必要があります。 私はprint文内の各値を表示することができますが、私はUILabelに割り当てるとき、私は私が親コレクションビューからのデータにロードし、データソースに割り当てるよfatal error: unexpectedly found nil while unwrapping an Optional value
Swift 3のネストされたコレクションビュー内のラベルに値を追加
を得る:
private var timeZone: [AlternativeTimeZone]!
var setTimeZones: [AlternativeTimeZone] {
get {
return self.timeZone
}
set {
self.timeZone = newValue
}
}
childcollectionviewService.setTimeZones = alternateTimesZonesData
サービスは、ビューコントローラを小さく保つために、親コレクションビューへのすべての参照を格納する外部クラスです。
ネストされたコレクションビューコードが標準的に見えます。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AlternateTimeZoneCell", for: indexPath) as? AlternateTimeZoneCell else { return UICollectionViewCell() }
print("Time Zone:", timeZone[indexPath.row].time)
cell.alternateTime.text = timeZone[indexPath.row].time
return cell
}
AlternativeTimeZone
は、テキスト文字列プロパティを持つ単純な構造体です。私はネストされたコレクションビューの内側にあるので、indexPathが子をオーバーライドすることができますか?
まだ同じ問題です。 – user7684436