Я пытаюсь получить доступ к ячейке в представлении коллекции, а затем изменить размер шрифта на полужирный, когда пользователь нажимает на ячейку, но у меня, похоже, возникают некоторые проблемы. При попытке доступа к выходам в моем представлении коллекции я получаю эту ошибку.Не удалось получить доступ к ячейке uicollectionview
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
Но я, похоже, не понимаю этого, потому что идентификаторы для ячейки верны, а также имя класса является правильным.
Протокол для работы с клеточной селекции
protocol InfiniteCollectionViewDelegate
{
func didSelectCellAtIndexPath(collectionView: UICollectionView, unmodifiedIndexPath: NSIndexPath, usableIndexPath: NSIndexPath)
}
Использование протокола
extension InfiniteCollectionView: UICollectionViewDelegate
{
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
infiniteDelegate?.didSelectCellAtIndexPath(self, unmodifiedIndexPath: indexPath, usableIndexPath: NSIndexPath(forRow: getCorrectedIndex(indexPath.row - indexOffset), inSection: 0))
}
}
Путь Я настраиваю вид коллекции
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, usableIndexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = navigationCollectionView.dequeueReusableCellWithReuseIdentifier("newsCell", forIndexPath: dequeueIndexPath) as! newsTypeCell
cell.newsTypeLbl.text = cellItems[usableIndexPath.row]
return cell
}
Действие для доступа к розетке ячейки просмотра коллекции
func didSelectCellAtIndexPath(collectionView: UICollectionView, unmodifiedIndexPath: NSIndexPath, usableIndexPath: NSIndexPath)
{
navigationCollectionView.scrollToItemAtIndexPath(unmodifiedIndexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: true)
let cell = navigationCollectionView!.cellForItemAtIndexPath(usableIndexPath) as! newsTypeCell
print(cell.newsTypeLbl.text)
}
Я пытаюсь напечатать значение в метке и попробовал то, что вы предложили сделать это: if let label = cell.newsTypeLbl {print (label.text)} ', но все, что происходит, это, кажется, сломать в этой строке' let cell = navigationCollectionView! .cellForItemAtIndexPath (usableIndexPath) как! newsTypeCell' – Tunds
что такое ошибка? –
Такая же фатальная ошибка: неожиданно обнаружена нуль при развертывании Необязательное значение (lldb) – Tunds