我正在尝试实现集合视图控制器。但是,由于一些随机的原因每次我运行iOS模拟器时图像都不会出现...而且,编译器不会给我任何错误...所以,我不知道我在这里缺少什么...
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!
}
答案 0 :(得分:2)
您需要为部分数量返回1。