2014-11-13 153 views
-1

我想實現一個集合視圖控制器。然而,對於一些隨機的原因,每次我運行iOS模擬器時都不會出現圖像...此外,編譯器不會給我帶來任何錯誤...所以,我不知道我在這裏丟失了什麼......CollectionViewController邏輯錯誤?

的CollectionView控制器

import UIKit 

let reuseIdentifier = "Cell" 

class CollectionViewController: UICollectionViewController { 

    var imagesCell : [String] = [] 

    @IBOutlet var collectionSaso: UICollectionView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

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

    // Do any additional setup after loading the view. 
    imagesCell = ["miEsposa.jpg", "miEsposa.jpg", "miEsposa.jpg"] 
} 

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

// MARK: UICollectionViewDataSource 

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


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

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

    let cell = collectionSaso.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell 

    // Configure the cell 
    cell.imageHolder.image = UIImage(named: imagesCell[indexPath.item]) 
    return cell 
} 

CollectionViewCell

import UIKit 

class CollectionViewCell: UICollectionViewCell { 

    @IBOutlet weak var imageHolder: UIImageView! 
} 

enter image description here

enter image description here

+0

您沒有看到Apple在numberOfSectionsInCollectionView方法中提供的警告嗎?你不應該忽視警告。 – rdelmar

回答

2

您需要返回1的段數。