【问题标题】:Swift UICollectionView inside UITableView onItemSelectUITableView onItemSelect 内的 Swift UICollectionView
【发布时间】:2015-08-21 22:51:04
【问题描述】:

我正在尝试创建一个类似于 iOS App Store 的布局。我已按照本教程进行操作:http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/

一切正常,但问题是本教程不包括点击 UICollectionView 单元格并转到新的 UIViewController。有没有人实施过?我是 Swift 的新手,所以我需要一点帮助。谢谢!

【问题讨论】:

    标签: ios swift uitableview uicollectionview


    【解决方案1】:

    为此,您需要转到 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)
    }
    

    【讨论】:

    • 这个问题是我没有 ViewCollectionController。我的 UICollectionView 在 TableViewCell 对象内。我无权访问 performSegueWithIdentifier() 或 self.storyboard 之类的东西。也许我误解了你的意思。
    【解决方案2】:

    所以我实际上得到了这个功能。可能不是最有效的,但就像我说的,Swift 不是我的驾驶室。无论如何,我只是将一个包含 UITableView 的 UIViewController 实例传递到 TableViewCell 中。然后我像 Usernumbernine 的回答一样调用 performSegueWithIdentifier()。

    【讨论】:

      猜你喜欢
      • 2019-01-07
      • 2016-02-16
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多