Please bear with me as I am new to swift. I am trying to create a Collection view of 10 restaurants in the city of NY. When a user clicks on the restaurant (A cell containing an image of the restaurant), I want a new collection view controller to be popped up with a collection view of the restaurants menu.
I want to be able to use one collection view controller to show the different menu each restaurant has when a user clicks on restaurant (a Cell).
I am using one prototype cell to populate all 10 restaurants. My difficulty now is how to get each cell to pop up that menu collection view controller with the set of menu for the particular restaurant chosen. The Menu collection view controller will show an image of the food, the name and the price( Almost like the way Instacart shows groceries when you choose a store. For now, I am only able to tap any cell and the same menu appears.
This is my restaurant list collection view controller. The DidSelect that has been commented was me trying to get the cells to be selected based on their Index path.
import UIKit
private let reuseIdentifier = "ManhattanCell"
class ManhattanCollectionViewController: UICollectionViewController {
var yourRest = [String]()
override func viewDidLoad() {
super.viewDidLoad()
yourRest = ["RestAwash",
"RestZoma",
"RestLeBaobab",
"RestSokhna",
"RestCoumba",
"RestMassawa",
"RestLesAmbassades",
"RestPonti",
"RestBraai",
"RestNewIvoire"]
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return yourRest.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! RestaurantCollectionViewCell
// Configure the cell
let image = UIImage(named: yourRest[indexPath.row])
cell.manhattanImageView.image = image
return cell
}
/* override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
// call your alert here
self.performSegueWithIdentifier("awashShowDetail", sender: self)
} else if indexPath.row == 1 {
self.performSegueWithIdentifier("testView", sender: self)
}
}
*/
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let sideSize = collectionView.frame.size.width / 2.51;
return CGSize(width: sideSize, height: sideSize);
}
}
Below is my RestaurantCollectionViewCell
import UIKit
class RestaurantCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var manhattanImageView: UIImageView!
}
My issue appears to be a little bit similar this question. I followed the answer and i'm still not able to get it to work.
Swift: UICollectionView selecting cell indexPath issues
Thanks.