I'm trying to make a collection view, and everything is working except when I try to select one cell.
My method didDeselectItemAtIndexPath
is not called.
In the main story board, I have a collectionviewcell
controller embed in a navigation view controller. The collectionviewC calls another controller to print details, between the two of them, there is a segue called segueDetailFeature
I have another project, and i did like that with a tableviewcontroller
and it works.
The images are well displayed, the print in the numebrofitemsinsection returns the good value.
Here is the code of my controller:
class ViewController: UICollectionViewController {
var listImageUrl = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// code to populate the listImageUrl
self.collectionView?.delegate = self
self.collectionView?.dataSource = self
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("nombre d'image : \(listImageUrl.count)")
return listImageUrl.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell
let imageView = cell.viewWithTag(1) as! UIImageView
let urlString: NSString = listImageUrl[indexPath.row] as NSString
let imgURL: NSURL = NSURL(string: urlString as String)!
//Télécharger une représentation NSData de l'image à cette URL
let imgData: NSData = NSData(contentsOfURL: imgURL)!
imageView.image = UIImage(data: imgData)
//imageView.image = UIImage(named: listImageUrl[indexPath.row])
return cell
}
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
print("selected item at index")
let urlImage = listImageUrl[indexPath.row]
imageUri = urlImage
performSegueWithIdentifier("segueDetailFeature", sender: collectionView)
}
}
I can't find why my code is not working, why my didDeselectItemAtIndexPath
is not called. Yet, when I run it, the app use the segue and load the detail controller, but it fails because one variable hasn't been instantiated in the method did select.
Thanks in advance