我有一個UICollectionView動態加載單元格,但我想打開一個不同的UIViewController當我推動單元格。 例如: -cell1打開UIViewController1 -cell2打開UIViewController2 -cell3打開UIViewController3UICollectionView不同segue爲每個UICollectionViewCell
是否有人知道,如果有可能使這個?
我有一個UICollectionView動態加載單元格,但我想打開一個不同的UIViewController當我推動單元格。 例如: -cell1打開UIViewController1 -cell2打開UIViewController2 -cell3打開UIViewController3UICollectionView不同segue爲每個UICollectionViewCell
是否有人知道,如果有可能使這個?
你需要創建一個視圖控制器塞格斯其中包含收集視圖(非單元格)到目標視圖控制器,例如:
UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc
記得爲每個賽段添加標識符。
並在代碼重寫UICollectionViewDelegate
方法
collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
哪個小區被竊聽(indexPath)該方法檢查中,如果這是小區1呼叫賽格瑞用正確的標識符:
performSegueWithIdentifier("goToVC1Identifier", sender: nil)
就做編程,像這樣在UICollectionViewDelegate
方法didSelectItemAtIndexPath
UIViewController *c = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%li",(long)indexPath.row]];
[self.navigationController pushViewController:c animated:YES];
//or however you a moving to next viewcontroller
確保您viewcontrollers有正確命名的標識符相匹配的細胞
你會需要在collectionview的代理的- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
中手動執行segue。