swift - 创建多个 segue 使用 CollectionView

标签 swift xcode

如下图所示,我有一个 CollectionViewCell 并且想创建多个 segue 到 TableViewController 和 ViewController。

如何创建多个 segue?

enter image description here

enter image description here

最佳答案

要为 TableViewController 和 ViewController 创建多个 segue,您需要创建一个从包含 Collection View (而非单元格)的 View Controller 到目标 View Controller 的 segue,例如:

UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc

请记住为每个 segue 添加标识符。

并在代码中覆盖UICollectionViewDelegate方法

collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

在该方法中检查哪个单元格被点击(indexPath),如果它是 cell1,则调用带有正确标识符的 segue:

performSegueWithIdentifier("goToVC1Identifier", sender: nil)

关于swift - 创建多个 segue 使用 CollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43403187/

相关文章:

ios - alamofire 通过 SOAP 发送请求

iphone - Xcode 忽略我的框架

ios - Xcode 7.3.1 : Set background image to UINavigationBar and display back button

xcode - 未找到更新错误的对象 Parse Swift

iOS 和 Armadillo (mach-o,但不是为 iOS 模拟器构建的)

ios - 删除 UITableView 中的行需要太多时间

swift - 让自动布局与 UIControl 子类一起工作

swift - 快速杀死进程

ios - 如何使用 Xcode 跟踪哪个项目增加了 iOS 中的内存?

swift - 如何在 Xcode 10 中解决链接器命令失败并退出代码 1(使用 -v 查看调用)