我有一个UICollectionView
<div class="parent">
<div class="line" style="">
<span class="text">AND</span>
</div>
</div>
然后在另一个我拥有的文件中
let cellIdentifier = "DayCollectionViewCell"
class ViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate {
@IBOutlet weak var button: UIButton!
var dates = [Date?]()
var startDate: Date?
@IBOutlet weak var daysCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
daysCollectionView.register(UINib.init(nibName: "DayCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: cellIdentifier)
let allDates = Helper.generateRandomDate(daysBack: 900, numberOf: 3)
self.dates = allDates.sorted(by: {
$0!.compare($1!) == .orderedAscending
})
print(self.dates)
startDate = self.dates.first! ?? Date()
daysCollectionView.delegate = self
daysCollectionView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 900
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = daysCollectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! DayCollectionViewCell //ON THIS LINE!!!!! Thread 1: EXC_BAD_ACCESS (code=1, address=0x5b9c38eb4f78)
let cellDate = Calendar.current.date(byAdding: .day, value: indexPath.item, to: self.startDate!)
if self.dates.contains(where: { Calendar.current.isDate(cellDate!, inSameDayAs: $0!) }) {
print("same")
cell.backgroundColor = UIColor.red
} else {
print("not me")
cell.backgroundColor = UIColor.lightGray
}
return cell
}
}
然后添加DayCollectionViewCell.xib文件:
我在这里做错了什么?