0

How can I go to a UIViewController from my UICollectionViewCell Class?

Here is my UICollectionViewCell Class :

class GalleryItemCollectionViewCell: UICollectionViewCell,UIAlertViewDelegate 
{
          @IBAction func gotoView(sender: AnyObject)
          {
             //I Want To Do It HERE... 
          }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0
self..window.rootViewController.performSegueWithIdentifier("nameOfSegueInStoryboard", sender: self)

This will transition to a view controller of your choice. To change variables in that view controller, you can use the prepareForSegue method under the view controller that contains the collection view:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "nameOfSegueInStoryboard" {
            let controller = segue.destinationViewController as! NameOfYourViewController
            controller.variable_name = new_value
        }
    }

This all relies on you adding a segue from your first view controller to the other and giving it an identifier in your storyboard.

brimstone
  • 3,370
  • 3
  • 28
  • 49
0

You will need to add a seguey to the storyboard then trigger it programmatically:

self.window.rootViewController.performSegueWithIdentifier("goToViewSeguey", sender: self)
Ahmed Nasser
  • 210
  • 1
  • 9