Я пытаюсь вставить представление коллекции внутри UIViewController:Xcode - UICollectionView внутри UIViewController
import UIKit
class imagesViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var labels = ["label1", "label2", "label3"]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
collectionView.backgroundColor = UIColor.redColor()
collectionView.delegate = self
collectionView.dataSource = self
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//#warning Incomplete method implementation -- Return the number of sections
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//#warning Incomplete method implementation -- Return the number of items in the section
return labels.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell
// Configure the cell
var title = UILabel(frame: CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height))
cell.contentView.addSubview(title)
title.text = labels[indexPath.row]
title.textColor = UIColor.yellowColor()
return cell
}
прогонов приложения, но это не не кажется, что представление коллекции должным образом связан с классом, ни один из конфигурации, которые я создал, просто отображаются. Как ни странно, мне пришлось копировать/вставлять функции для представления коллекции, потому что автозаполнение показывает только некоторые методы коллекции.