performSelect来自CollectionViewCell didSelectItemAt在导航和tabbarcontroller中

时间:2018-02-16 13:53:15

标签: ios swift segue uicollectionviewcell

我疯了,因为我只能使用模态弹出窗口。我的目标是将destinationVC保留在导航和tabbarcontroller中。

从我所有评论的代码中可以看出,我已经尝试了很多。有些代码会使应用程序崩溃,有些代码在点击单元格时根本不会产生影响。

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    let Storyboard = UIStoryboard(name: "Main", bundle: nil)
    let DestinationViewController : PlayEpisodeViewController = Storyboard.instantiateViewController(withIdentifier: "PlayEpisodeViewController") as! PlayEpisodeViewController

    DestinationViewController.getEpisodeName = episodesArray[indexPath.row].EpisodeName
    DestinationViewController.getEpisodeFileURL = episodesArray[indexPath.row].EpisodeURL
    DestinationViewController.getEpisodeImage = episodesArray[indexPath.row].EpisodeImage

    let navController = UINavigationController(rootViewController: DestinationViewController)
    //UIApplication.shared.keyWindow?.rootViewController?.show(navController, sender: Any?.self)
    //.pushViewController(DestinationViewController, animated: true)
    UIApplication.shared.keyWindow?.rootViewController?.present(navController, animated: true, completion: nil)
    //performSegue(withIdentifier: "playEpisodeSegue", sender: self)
    //shouldPerformSegue(withIdentifier: String, sender: self)
    //show(navigationController, sender: Any?.self)
    //present(navigationController, animated: true, completion: nil)        
}

1 个答案:

答案 0 :(得分:1)

  1. 尽量保持单一责任原则,并在课堂内尽可能多地填充。 (即避免使用UIApplication.shared.keyWindow?.rootViewController?等)

  2. 使用storyboard组织它的最简单方法: 选择你的集合视图控制器,将其嵌入到导航控制器中,将其嵌入到标签栏中(或者可以添加" ViewControllers"从标签栏控制器到导航控制器的搜索)

  3. Like this!