[英]how to navigate or show other view controller when indexPath cell pressed
i have one collection view with 2 cells
. 我有
2 cells
一个集合视图。 So by default first cell will be 0,1......
And i also have 2 viewcontroller
. 所以默认情况下,第一个单元格将是
0,1......
而且我还有2 viewcontroller
。 Named 1. firstVC, 2. secondVC
. 分别命名为
1. firstVC, 2. secondVC
。 What i need is, when i tap cell 1 it should show the firstVC
as a modal
view segue
. 我需要的是,当我点击单元格1时,它应该将
firstVC
显示为modal
视图segue
。
same like when i press second cell, it should show the secondVC
as a modal
view segue
.. 就像当我按下第二个单元格一样,它应该显示第二个
secondVC
作为modal
视图segue
..
How to do that, here i can print which cell i am selecting. 如何做到这一点,在这里我可以打印我选择的单元格。 How to show that viewcontrollers ??
如何显示那个viewcontrollers?
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")
}
}
please help me out...Thanks !! 请帮帮我...谢谢!
Use self.presentViewController(UIViewController, animated: Bool)
or add segue in the Interface Builder and call it using self.performSegueWithIdentifier(String, sender: AnyObject?)
. 使用
self.presentViewController(UIViewController, animated: Bool)
或在界面生成器中添加segue,然后使用self.performSegueWithIdentifier(String, sender: AnyObject?)
调用。 Also when adding segue in the IB make sure to change it to "present modally" if you need to. 另外,在IB中添加segue时,请确保将其更改为“模态显示”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.