2015-05-23 14 views
5

Tôi có UICollectionViewController trong bảng phân cảnh đã được liên kết với một tệp có tên là XCollectionViewController.swift là lớp con của UICollectionViewController.Các ô không xuất hiện trong UICollectionView?

Mã của tôi là như sau:

super.viewDidLoad() 
    // Register cell classes 
    self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 
} 


    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
    //#warning Incomplete method implementation -- Return the number of sections 
    return 4 
} 


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    //#warning Incomplete method implementation -- Return the number of items in the section 
    return 10 
} 

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UICollectionViewCell 

    // Configure the cell 

    return cell 
} 

Tôi có định tái sử dụng cho các tế bào thiết lập như là nó được đặt tên trong file.

Khi chạy, tôi có thể nhìn thấy nền của CollectionView, nhưng không nhìn thấy 40 ô mà tôi sẽ thấy. Chuyện gì thế?

Trả lời

7

Chỉ cần xóa dòng này trong phương thức viewDidLoad sẽ hiển thị 40 ô của bạn.

self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 
+1

Tại sao? Và làm thế nào để tôi tham khảo một mã định danh tái sử dụng nếu tôi chưa định nghĩa gì? –

+0

@LukasKalinski Bạn có thể đặt số nhận dạng sử dụng lại trong bảng phân cảnh của mình. – tounaobun

+0

Cảm ơn bạn đã trả lời. Tôi vừa mới nhận ra tôi đã hiểu sai câu trả lời của bạn. Lấy làm tiếc! –

Các vấn đề liên quan