0

Program aracılığıyla bir UICollectionView oluşturuyorum. Ben ViewControllerA tarafından kontrol edilen bir UIScrollView bir film şeridi varUICollectionViewCell görünmüyor

: http://randexdev.com/2014/07/uicollectionview/ aşağıdaki

Yani benim kurulum gibi: Bir reddi olarak

, bu öğretici izledi. Ayrı bir sınıfta

CustomCollectionViewController Aşağıdaki kod var: Bu kodu var benim ViewControllerA yılında

import Foundation 
import UIKit 

class CustomCollectionViewController : UICollectionViewController, UICollectionViewDelegateFlowLayout { 

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { 

     let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() 
     layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10) 
     layout.itemSize = CGSize(width: 90, height: 120) 

     super.init(collectionViewLayout: layout) 

     collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) 
     //collectionView = UICollectionView(frame: CGRectMake(0, 0, 500, 500), collectionViewLayout: layout) 
     collectionView!.dataSource = self 
     collectionView!.delegate = self 
     collectionView!.backgroundColor = UIColor.redColor() 
     collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell") 
     self.view.addSubview(collectionView!) 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 14 
    } 

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) 
     cell.backgroundColor = UIColor.greenColor() 
     return cell 
    } 
} 

let collectionViewController: CustomCollectionViewController = CustomCollectionViewController(nibName: nil, bundle: nil) 
collectionViewController.view.frame.origin = CGPointMake(scrollViewWidth*3, 0) 

scrollView.addSubview(collectionViewController.view) 

simülatörde çalıştırırsanız, ben arka planını kırmızı görebilirsiniz UICollectionView, ancak hiçbir hücre yok.

Neyi yanlış yaptığımı ima ediyor musunuz?

+0

içinde childViewController olarak ViewController set vermedi oldu? – dirkgroten

+0

@dirkgroten Zaten yaptım. Bu çağrılıyor. – Phytochrome

cevap

0

sorun ben size CollectionView'ın bir kesme noktası ayarlamak Can viewControllerA

self.addChildViewController(collectionViewController) 
collectionViewController.didMoveToParentViewController(self) 
1

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath eksik olabilir! cellForItemAtIndexPath: fonksiyonu ve denir alırsa bakın

+0

Sadece "func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {return CGSizeMake (90, 120)}' yi denedim ve ekledim, ancak hiçbir şey değişmedi. – Phytochrome

+0

Görünüm denetleyiciniz UICollectionViewController alt sınıfını UIViewController OR olarak değiştirmeyi deneyin VEYA self.collectionView = sizinCollectionView öğenizi deneyin – iOS77

+0

Nope. Hiçbir değişiklik yok. – Phytochrome

İlgili konular