我有包含集合視圖的視圖。我以編程方式添加了這個集合視圖(在viewDidLoad中) - 所以這不在故事板上。此收集視圖包含多個單元格。當用戶點擊集合視圖中的一個單元格時,我想繼續使用不同的視圖控制器(我打算在故事板上添加)。我的問題是 - 由於收集視圖不在故事板上,所以我怎麼能從中解脫出來?或者還有其他方法可以實現這一點。從子視圖中使用segue
某些更新上面的原題:
在父視圖控制器,我做了以下內容:
//Layout for the collection view
CDLayout *cdLayout = [[CDLayout alloc] initWithItemSize:CGSizeMake(cardWidth, cardHeight) withItemInsets:UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset) withInterItemSpacingX:8.0f withTopMargin:margin withLeftMargin:margin withBottomMargin:margin withRightMargin:margin shouldRotate:NO];
//This is the collection view controller
CDLineLayoutViewController *cdLineVC = [[CDLineLayoutViewController alloc] initWithCollectionViewLayout:cdLayout withItemCount:12 ];
// add the collection view controller to self - the parent
[self addChildViewController:cdLineVC];
[cdLineVC didMoveToParentViewController:self];
// add collectionView as a subview
[self.view addSubview:cdLineVC.collectionView];
的的CollectionView有12卡。當用戶點擊我想要移動到另一個視圖控制器的卡片之一時。
正如你所看到的集合視圖不在故事板上。那麼,有沒有辦法創建一個segue?
順便說一句,一個選項是Taseen在下面提出的建議。我試過了,它正在工作。但據我所知,它實際上並不是一個「繼續」。
我將如何識別集合視圖中的哪個項目被選中(或點擊)?不應該有一種方法來處理子視圖(在這種情況下,集合視圖)控制器中的segue。 –
作爲performSegueWith ...方法的第二個參數的sender對象是tapped對象。每個視圖對象都有NSInteger屬性_tag_。指定一個唯一編號的視圖對象。用這個數字你可以識別被點擊的視圖對象。 –
可能是簡單的方法是不使用segues。 @Taseen解決方案是更好的方法。 –