Hello Richard Turton,
In this Tutorial: UICollectionView Tutorial Part 2: Reusable Views and Cell Selection
i have saved your completed project and run with my xcode. the compiler has error that my image below, please help me!
Thanks,
my xcode’s version Version 7.3.1 (7D1014).
The tutorial is out of date - a new version is being worked on.
Part 2: CollectionView Tutorial:
I am getting an error removing the cell method below:
The error is => ‘find’ is unavailable: call the ‘indexOf()’ method on the collection
** ‘find’ has been explicitly marked unavailable here (Swift.find)**
And remove them when the cell is deselected (tapped again):
override func collectionView(collectionView: UICollectionView!,
didDeselectItemAtIndexPath indexPath: NSIndexPath!) {
if sharing {
if let foundIndex = find(selectedPhotos, photoForIndexPath(indexPath)) {
selectedPhotos.removeAtIndex(foundIndex)
updateSharedPhotoCount()
}
}
}
Hi
I will put nib file in collection view heade and create image slider in header
do you are way , please help me
razipour1993@gmail.com
Hey, I had the same problem as you. Running Xcode 7.3.1, Swift 2.2
This is what I did to fix it:
var resultsDictionary : AnyObject?
do
{
resultsDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(rawValue: 0)) as? NSDictionary
}
catch let JSONError as NSError? {
if JSONError != nil {
completion(results: nil, error: JSONError)
return
}
}
Insert that block of code below the if error != nil{} block, and above the switch statement. Should work!
The find() is deprecated, so you have get the index from the Array’s indexOf() method. So replace that line with:
let selectedPhoto = self.photoForIndexPath(indexPath)
if let foundIndex = self.selectedPhotos.indexOf(selectedPhoto) {
That should work, and hopefully makes sense to you. Good luck!
Also, one more thing to note is that the implementation of the UIActivityViewController using the UIPopOverController (The last block of code in the tutorial) is deprecated in iOS 9.
let shareScreen = UIActivityViewController(activityItems: imageArray, applicationActivities: nil)
let popover = UIPopoverController(contentViewController: shareScreen)
popover.presentPopoverFromBarButtonItem(self.navigationItem.rightBarButtonItems!.first as! UIBarButtonItem,
permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
I replaced this with the following code. Also, I added an extra bit to make it work for the iPhone as well!
// Present UIActivityViewController for iPad
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
let shareScreen = UIActivityViewController(activityItems: imageArray, applicationActivities: nil)
let sourceButton = self.navigationItem.rightBarButtonItems!.first! as UIBarButtonItem
shareScreen.modalPresentationStyle = .Popover
shareScreen.popoverPresentationController?.permittedArrowDirections = .Any
shareScreen.popoverPresentationController?.barButtonItem = sourceButton
self.presentViewController(shareScreen, animated: true, completion: nil)
}
// Present UIActivityViewController for iPhone!
else if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
// Separate Activity View Controller to present for iPhones
let activityVC = UIActivityViewController(activityItems: imageArray, applicationActivities: nil)
let sourceView = self.view
activityVC.popoverPresentationController?.sourceView = sourceView
self.presentViewController(activityVC, animated: true, completion: nil)
}