Я собираюсь сделать обзор продуктов, используя пользовательские ячейки в коллекции. Я все установил, я не получаю ошибок, но каким-то образом содержимое ячейки не отображается.UICollectionViewController, не отображающий подзаголовки пользовательского UICollectionViewCell
У меня есть
- создал подкласс UICollectionViewCell
- добавлены все подвиды в раскадровке и соединил их, как IBOutlets к моему классу
- зарегистрировал пользовательскую ячейку с помощью
self.collectionView!.registerClass(ProductCell.self, forCellWithReuseIdentifier: reuseIdentifier)
- проверил источник данных, нет там ошибки. вот numberOfItemsInSection:
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var items: Int = 0
if (section == 0) {
if (currentCategory == nil) {
items = sharedStore.categories.count
} else {
items = currentCategory.categories.count
}
} else if (section == 1) {
if (currentCategory == nil) {
items = sharedStore.products.count
} else {
items = currentCategory.items.count
}
}
return items
}
- настроить cellForItemAtIndexPath:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProductCell
cell.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.05)
cell.layer.cornerRadius = 5
//initialize shit
cell.titleLabel = UILabel()
cell.priceLabel = UILabel()
if(indexPath.section == 0) {
let current: Category!
//get model object
if(currentCategory == nil) {
if(sharedStore.categories.count > 0) {
current = sharedStore.categories[indexPath.row] as! Category
} else {
current = nil
}
} else {
if(currentCategory.categories.count > 0) {
current = currentCategory.categories[indexPath.row] as! Category
} else {
current = nil
}
}
cell.itemImage = UIImageView(image: UIImage(named: "folderImage.png"))
cell.itemImage.hidden = false
cell.titleLabel.text = current.title as String
cell.priceLabel.hidden = true
}
return cell
}
ячейка пуста. Нет изображения, нет названия и нет ценника. Я знаю, что источник данных работает правильно, потому что когда я добавляю продукт, он показывает новую ячейку.
Любые предложения о том, как я могу получить свои предметы в камере?
Любая помощь будет высоко оценен :)
Где вы возвращаете ячейку? Можете ли вы отправить больше кода (особенно numberOfItemsInSection) –
спасибо, что при копировании кода он должен был пропустить. Я также добавил numberOfItemsInSection. – Joris416
Пока все хорошо. Как насчет numberOfSectionsInCollectionView? Также вы установили делегат в свой коллекционный вид? –