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 打开另一个视图控制

      Swift - how to open another viewcontroller with CollectionViewCell inside UITableViewCell(Swift - 如何在 UITableViewCell 中使用 CollectionViewCell 打开另一个视图控制器)
        <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 打开另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

                • <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>
                            <tbody id='TnmTC'></tbody>

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