1. <legend id='ClizJ'><style id='ClizJ'><dir id='ClizJ'><q id='ClizJ'></q></dir></style></legend>

        <bdo id='ClizJ'></bdo><ul id='ClizJ'></ul>
    2. <i id='ClizJ'><tr id='ClizJ'><dt id='ClizJ'><q id='ClizJ'><span id='ClizJ'><b id='ClizJ'><form id='ClizJ'><ins id='ClizJ'></ins><ul id='ClizJ'></ul><sub id='ClizJ'></sub></form><legend id='ClizJ'></legend><bdo id='ClizJ'><pre id='ClizJ'><center id='ClizJ'></center></pre></bdo></b><th id='ClizJ'></th></span></q></dt></tr></i><div id='ClizJ'><tfoot id='ClizJ'></tfoot><dl id='ClizJ'><fieldset id='ClizJ'></fieldset></dl></div>

      <small id='ClizJ'></small><noframes id='ClizJ'>

    3. <tfoot id='ClizJ'></tfoot>

      Swift - 如何在 UITableViewCell 中使用 CollectionViewCell 打开另一个视图控制

      时间:2023-09-12
        <bdo id='idN8w'></bdo><ul id='idN8w'></ul>
        1. <legend id='idN8w'><style id='idN8w'><dir id='idN8w'><q id='idN8w'></q></dir></style></legend>
            <tbody id='idN8w'></tbody>

          <small id='idN8w'></small><noframes id='idN8w'>

            1. <i id='idN8w'><tr id='idN8w'><dt id='idN8w'><q id='idN8w'><span id='idN8w'><b id='idN8w'><form id='idN8w'><ins id='idN8w'></ins><ul id='idN8w'></ul><sub id='idN8w'></sub></form><legend id='idN8w'></legend><bdo id='idN8w'><pre id='idN8w'><center id='idN8w'></center></pre></bdo></b><th id='idN8w'></th></span></q></dt></tr></i><div id='idN8w'><tfoot id='idN8w'></tfoot><dl id='idN8w'><fieldset id='idN8w'></fieldset></dl></div>
              • <tfoot id='idN8w'></tfoot>
                本文介绍了Swift - 如何在 UITableViewCell 中使用 CollectionViewCell 打开另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我真的是 iOS/Swift 的新手,而且我在做一个小项目.在这个项目中,我在 ViewController 中有一个 UITableView.我在 UITableViewCell 中有另一个文件自定义 CollectionViewCell.我希望当用户单击 collectionview 中的一个单元格时,它将打开另一个 ViewController 并从此 collectionviewcell 获取数据.这是我的 uitableview swift 文件:

                I'm really new in iOS/Swift and i'm in a small project. In this project i have a UITableView inside ViewController. And i have another file custom CollectionViewCell in side UITableViewCell. I want when user click a cell in collectionview it will open another ViewController and it get data from this collectionviewcell. This is my uitableview swift file:

                class IndexRow: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
                var names:[String] = ["Movie 1","Movie 2","Movie 3","Movie 4","Movie 5","Movie 6"]
                @IBOutlet weak var collectionView: UICollectionView!
                override func awakeFromNib() {
                    super.awakeFromNib()
                    collectionView.registerClass(indexOneMovie.self, forCellWithReuseIdentifier: "onemovie")
                    let nib = UINib(nibName: "indexOneMovie",bundle: nil)
                    collectionView.registerNib(nib, forCellWithReuseIdentifier: "onemovie")
                    self.collectionView.backgroundColor = UIColor.clearColor()
                    self.collectionView.delegate = self
                    self.collectionView.dataSource = self
                    print("Hello")
                }
                func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                    return names.count
                }
                
                func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
                    let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("onemovie", forIndexPath: indexPath) as! indexOneMovie
                    cell.poster.image = UIImage(named: "poster.jpg")
                    cell.name.text = names[indexPath.row]
                    return cell
                }
                
                func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
                    print(indexPath.item)
                }
                
                func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
                    let itemsPerRow:CGFloat = 2
                    let hardCodedPadding:CGFloat = 0
                    let itemWidth = (collectionView.bounds.width / itemsPerRow) - hardCodedPadding
                    let itemHeight = collectionView.bounds.height - (hardCodedPadding)
                    return CGSize(width: itemWidth, height: itemHeight)
                }
                

                我该怎么做?

                推荐答案

                你可以这样:

                func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
                    print(indexPath.item)
                    let name = names[indexPath.item]
                    let distinationViewController = DistinationViewController()
                    distinationViewController.name = name
                    if let navVC: UINavigationController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UINavigationController {
                    navVC.pushViewController(distinationViewController, animated: true)
                    }
                }
                

                这只是一种方法,我不知道您要推送哪个视图或您的名称数组包含什么,因此请相应地更改这些内容.

                This is just a way to do it i dont know which view you want to push or what your names array contains so kindly change those things accordingly.

                从 uiapplication 获取 root navigationcontroller 并对其执行推送.

                get root navigationcontroller from uiapplication and perform push on it.

                这篇关于Swift - 如何在 UITableViewCell 中使用 CollectionViewCell 打开另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Swift,对于某些 UIViews 到他们的整体控制器单击时 下一篇:Swift 不能通过委托调用协议方法

                相关文章

              • <i id='TnmTC'><tr id='TnmTC'><dt id='TnmTC'><q id='TnmTC'><span id='TnmTC'><b id='TnmTC'><form id='TnmTC'><ins id='TnmTC'></ins><ul id='TnmTC'></ul><sub id='TnmTC'></sub></form><legend id='TnmTC'></legend><bdo id='TnmTC'><pre id='TnmTC'><center id='TnmTC'></center></pre></bdo></b><th id='TnmTC'></th></span></q></dt></tr></i><div id='TnmTC'><tfoot id='TnmTC'></tfoot><dl id='TnmTC'><fieldset id='TnmTC'></fieldset></dl></div>
              • <small id='TnmTC'></small><noframes id='TnmTC'>

                    <bdo id='TnmTC'></bdo><ul id='TnmTC'></ul>
                  1. <tfoot id='TnmTC'></tfoot>
                    <legend id='TnmTC'><style id='TnmTC'><dir id='TnmTC'><q id='TnmTC'></q></dir></style></legend>