简体   繁体   English

在UITableView onItemSelect内的Swift UICollectionView

[英]Swift UICollectionView inside UITableView onItemSelect

I am trying to create a layout much like the iOS App Store. 我正在尝试创建类似于iOS App Store的布局。 I have followed this tutorial: http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/ 我遵循了本教程: http : //ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/

Everything is working but the problem is that this tutorial does not cover tapping on a UICollectionView cell and segueing to a new UIViewController. 一切正常,但问题在于本教程不涉及点击UICollectionView单元格并选择到新的UIViewController。 Has anyone implemented that? 有人实施过吗? I am new at Swift, so I need a little help. 我是Swift的新手,所以我需要一些帮助。 Thanks! 谢谢!

To do that you need to go to your ViewCollectionController and override the didSelectItemAtIndexPath method. 为此,您需要转到ViewCollectionController并重写didSelectItemAtIndexPath方法。

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let controller = self.storyboard?.instantiateViewControllerWithIdentifier("yourControllerIdHere") as UIViewController
    presentViewController(controller, animated: true, completion: nil)
}

if you have a segue set up already then just do 如果您已经设置了segue,那么只需

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("yourSeguesIdentifier", sender: self)
}

So I actually got this functional. 所以我实际上得到了这个功能。 Probably not the most efficient, but like I said, Swift is not my wheelhouse. 可能不是最有效的,但是就像我说的那样,Swift不是我的操舵手。 Anyway I just passed an instance of the UIViewController that contains the UITableView into the TableViewCell. 无论如何,我只是将包含UITableView的UIViewController实例传递到TableViewCell中。 Then I call performSegueWithIdentifier() like in Usernumbernine's answer. 然后,像Usernumbernine的答案一样,调用performSegueWithIdentifier()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM