gpt4 book ai didi

ios - 按下 indexPath 单元格时如何导航或显示其他 View Controller

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:10 25 4
gpt4 key购买 nike

我有一个包含 2 个单元格 的 Collection View 。所以默认情况下第一个单元格将是 0,1...... 我还有 2 viewcontroller。命名为 1。 firstVC, 2.secondVC.我需要的是,当我点击单元格 1 时,它应该将 firstVC 显示为 modal View segue

就像我按下第二个单元格时一样,它应该将 secondVC 显示为 modal View segue..

如何做到这一点,在这里我可以打印我选择的单元格。如何显示 View Controller ??

   func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// You can use indexPath to get "cell number x", or get the cell like:
let cell = collectionView.cellForItemAtIndexPath(indexPath)

if((indexPath.row) == 0) {
print("Layout 1 clicked")

}
else if((indexPath.row) == 1) {
print("Layout 2 clicked")
}
else if((indexPath.row) == 2) {
print("Layout 3 clicked")
}
else if((indexPath.row) == 3) {
print("Layout 4 clicked")
}


}

请帮帮我...谢谢!!

最佳答案

使用 self.presentViewController(UIViewController, animated: Bool) 或在 Interface Builder 中添加 segue 并使用 self.performSegueWithIdentifier(String, sender: AnyObject?) 调用它.此外,在 IB 中添加 segue 时,如果需要,请确保将其更改为“模态呈现”。

关于ios - 按下 indexPath 单元格时如何导航或显示其他 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36071180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com