ios - 从 collectionview 过渡到多个 View Controller

标签 ios swift

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
    if (indexPath.row == 0){
        self.performSegueWithIdentifier("showDetail", sender: self)
    }
    if (indexPath.row == 1){
        self.performSegueWithIdentifier("showSoldi", sender: self)
    }
}

问题是两个 View Controller 都被调用了。首先是 segue 本身,然后是这段代码。有什么解释吗?

最佳答案

您的 segues 正在触发,因为您已将它们从 Collection View 的单元格连接起来。如果您希望能够从代码中调用您的 segue,请将它们连接到 viewController 顶部的 viewController 图标。

How to wire segue from viewController

通过这种方式,转场只会在您调用 performSegueWithIdentifier 时触发。

关于ios - 从 collectionview 过渡到多个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32155727/

相关文章:

ios - 不是在 IB 中创建的 UILabel 的自动换行?

ios - 魔法记录在单独的线程中创建/获取实体

iphone - 如何使用 twitter api v1.1 获取用户详细信息(Twitter 错误 215)

ios - 在 UIScrollView 中缩放 UIImageView – 不居中

ios - 推送通知在 IOS 11 中不起作用

swift - PFTwitter Swift 实用程序

iOS MQTT 客户端框架 : 'SocketRocket/SRWebSocket.h' file not found

ios - 当 AdMob 中的 GADRewardBasedVideoAd 关闭时,选项卡 Controller 也会关闭

ios - 参数标签 '(_:, heightForRowAt:)' 与任何可用的重载都不匹配

ios - cell.imageView 不显示图像