[英]Swift UICollectionView inside UITableView onItemSelect
我正在尝试创建类似于iOS App Store的布局。 我遵循了本教程: http : //ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/
一切正常,但问题在于本教程不涉及点击UICollectionView单元格并选择到新的UIViewController。 有人实施过吗? 我是Swift的新手,所以我需要一些帮助。 谢谢!
为此,您需要转到ViewCollectionController并重写didSelectItemAtIndexPath方法。
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("yourControllerIdHere") as UIViewController
presentViewController(controller, animated: true, completion: nil)
}
如果您已经设置了segue,那么只需
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("yourSeguesIdentifier", sender: self)
}
所以我实际上得到了这个功能。 可能不是最有效的,但是就像我说的那样,Swift不是我的操舵手。 无论如何,我只是将包含UITableView的UIViewController实例传递到TableViewCell中。 然后,像Usernumbernine的答案一样,调用performSegueWithIdentifier()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.