2016-05-24 21 views
7

Film şeridinde UICollectionViewController oluşturdum. Ama akıcı hale gelmek için akmam gerekiyor ... Flowlayout'a nasıl erişir ve kullanırım? İşte denetleyicim: collectionView.flowlayout'u kullanma çalışmadı.Toplama görünümünün akış hızı nasıl artırılır?

class TableCollectionViewController: UICollectionViewController,UICollectionViewDelegateFlowLayout { 

    var json: JSON? 

    override func viewDidLoad() { 
     super.viewDidLoad() 


     // Uncomment the following line to preserve selection between presentations 
     // self.clearsSelectionOnViewWillAppear = false 

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

     // Do any additional setup after loading the view. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
     let cellWidth = collectionView.bounds.width/(CGFloat(json!["Rows"][0]["Column"].count)+1) 

     return CGSizeMake(cellWidth, 100) 
    } 


    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
     // #warning Incomplete implementation, return the number of sections 
     return json!["Rows"].count 
     //return 5 
    } 

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     // #warning Incomplete implementation, return the number of items 
     return json!["Rows"][section]["Column"].count 
     //return 5 
    } 

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyTableCell", forIndexPath: indexPath) as! MyTableCollectionViewCell 
     cell.backgroundColor = UIColor.whiteColor() 

     cell.label.text = json!["Rows"][indexPath.section]["Column"][indexPath.row].stringValue 
     cell.label.lineBreakMode = .ByWordWrapping 
     cell.label.numberOfLines = 0 
     //cell.label.text = "deneme" 

     // Configure the cell 

     return cell 
    } 
} 

cevap

13

o collectionView.collectionViewLayout ama aynı collectionViewLayout değişkeni kullanan

9

ihtiyacınız UICollectionViewFlowLayout sınıf UICollectionViewLayout bir alt sınıfıdır akış düzeni olarak döküm gerekir:

if let collectionViewFlowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout { 

    // Use collectionViewFlowLayout 

} 
İlgili konular