Swift - how to open another viewcontroller with CollectionViewCell inside UITableViewCell

后端 未结 2 437
南笙
南笙 2021-01-16 16:54

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 si

2条回答
  •  爱一瞬间的悲伤
    2021-01-16 17:27

    You can do it like this :

    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.

    get root navigationcontroller from uiapplication and perform push on it.

提交回复
热议问题