開始練習Swift。在singleViewController
我試圖做一個UICollectionView
。在故事板中,我設置了dataSource
和delegate
。在這裏,我得到的錯誤:類型不符合協議Swift
'UICollectionView' does not conform to protocol 'UICollectionViewDataSource'
import UIKit
class galeriacontroler: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
@IBOutlet weak var collectionview: UICollectionView!
let fotosgaleria = [UIImage(named: "arbol3"), UIImage(named:"arbol4")]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.fotosgaleria.count
}
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cellImagen", forIndexPath:indexPath) as! cellcontroler
cell.imagenView2?.image = self.fotosgaleria[indexPath.row]
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("showImage", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showImage"
{
let indexPaths = self.collectionview!.indexPathsForSelectedItems()
let indexPath = indexPaths![0] as NSIndexPath
let vc = segue.destinationViewController as! newviewcontroler
vc.image = self.fotosgaleria[indexPath.row]!
}
}
}