2015-07-21 41 views
0

我遇到问题。我有一个ViewController1包含tableView.that的tableView创建自定义tableViewCell将自定义表格中的uicollectionview数据传递给视图控制器

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    TableCategoryCell *cell = (TableCategoryCell *)[tableView dequeueReusableCellWithIdentifier:CategoryCellIndentifier]; 
} 

在TableCategoryCell.m包含的CollectionView自定义单元格。

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    UICollectionViewCell *cell_collection = [collectionView dequeueReusableCellWithReuseIdentifier:COLLECTION_CELL_IDENTIFIER forIndexPath:indexPath]; 
} 

现在我想用户点击的CollectionView项didSelectItemAtIndexPath方法打开新ViewController2和数据传递到视图控制器2?

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UINavigationController *navigationController =[storyboard instantiateViewControllerWithIdentifier:@"Navigation"]; 
    ViewController2 *watchController = [storyboard instantiateViewControllerWithIdentifier:WATCH_IDENTIFIER]; 
    [navigationController pushViewController:watchController animated:YES]; 
} 

我可以在故事板从集合项目推ViewController2但我不知道在编程? 我该怎么办?

+0

所以,如果你在集合视图中选中该单元格,应该推到第二个视图控制器。你是这个意思吗? –

+0

是的..我不知道如何推到2nd ViewController –

回答

0

实施uicollection视图的委托方法:

- (void)tableView:(UICollectionView *)tableView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //check if you tap on cell 1 
    if(inderPath.row==0){ 
      //then push to second view controller 
      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" 
                bundle: nil]; 
      SecondViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"your-second-view-controller-ID"]; 
     [self.navigationController pushViewController:viewController animated:YES]; 
    } 

} 
+0

我不能在didSelectItemAtIndexPath中调用self.storyboard?我检查了单元格上的事件点击。这是Viewcontroller2.h ** @界面ViewController2:UITableViewCell ** –

+0

你不使用故事板?我编辑了我的答案。试试 –

+0

是的。我使用Main.storyboard,我的日程安排为:navigationController-> VC0插入VC1 - > push到VC2。我认为VC1是VC0的子集,因此可以调用self.storyboard。 –

相关问题