[英]How to navigate to some other View Controller when Navigation Controller back button is pressed?
[英]how to navigate or show other view controller when indexPath cell pressed
我有2 cells
一個集合視圖。 所以默認情況下,第一個單元格將是0,1......
而且我還有2 viewcontroller
。 分別命名為1. firstVC, 2. secondVC
。 我需要的是,當我點擊單元格1時,它應該將firstVC
顯示為modal
視圖segue
。
就像當我按下第二個單元格一樣,它應該顯示第二個secondVC
作為modal
視圖segue
..
如何做到這一點,在這里我可以打印我選擇的單元格。 如何顯示那個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")
}
}
請幫幫我...謝謝!
使用self.presentViewController(UIViewController, animated: Bool)
或在界面生成器中添加segue,然后使用self.performSegueWithIdentifier(String, sender: AnyObject?)
調用。 另外,在IB中添加segue時,請確保將其更改為“模態顯示”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.