V
V
Vasily Vorobyov2016-04-28 14:57:25
Swift
Vasily Vorobyov, 2016-04-28 14:57:25

Why doesn't UICollectionViewCell work?

My ViewController which has a UICollectionView inside. I use it exclusively as a table into which data from JSON is driven. There are 16 cells inside, with identifiers cell1-cell16

class FirstViewController: UICollectionViewController {

    @IBOutlet weak var table: UICollectionView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        table.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier:"cell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell
    {
        var  cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell1", forIndexPath: indexPath) as UICollectionViewCell
        return cell
    }
}
При запуске получаю ошибку

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] loaded the "9pv-A4-QxB-view-tsR-hK-woN" nib but didn't get a UICollectionView.

If you just drag UICollectionView - does not display cells.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rettpop, 2016-04-29
@rettpop

I assume that you first threw the UIViewController controller on the storyboard, and then tied the UICollectionViewController to the sorters. And now ksibina expects that the first view in the hierarchy will be UICollectionView. And you have a UIView there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question