Swift 从UICollectionViewCell类转到ViewController
如何从UICollectionViewCell类转到UIViewController 以下是我的UICollectionViewCell类:Swift 从UICollectionViewCell类转到ViewController,swift,viewcontroller,Swift,Viewcontroller,如何从UICollectionViewCell类转到UIViewController 以下是我的UICollectionViewCell类: class GalleryItemCollectionViewCell: UICollectionViewCell,UIAlertViewDelegate { @IBAction func gotoView(sender: AnyObject) { //I Want To Do It HE
class GalleryItemCollectionViewCell: UICollectionViewCell,UIAlertViewDelegate
{
@IBAction func gotoView(sender: AnyObject)
{
//I Want To Do It HERE...
}
}
这将过渡到您选择的视图控制器。要更改该视图控制器中的变量,可以使用包含集合视图的视图控制器下的prepareforsgue
方法:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "nameOfSegueInStoryboard" {
let controller = segue.destinationViewController as! NameOfYourViewController
controller.variable_name = new_value
}
}
这一切都取决于您将一个序列从第一个视图控制器添加到另一个视图控制器,并在情节提要中为其提供一个标识符。您需要将一个序列添加到情节提要,然后以编程方式触发它:
self.window.rootViewController.performSegueWithIdentifier("goToViewSeguey", sender: self)
如果您使用的是故事板:
self.window.rootViewController.performSegueWithIdentifier("goToViewSeguey", sender: self)