【问题标题】:pass data from uicollectionview in custom tablecell to viewcontroller将数据从自定义表格单元中的 uicollectionview 传递到 viewcontroller
【发布时间】:2015-07-21 14:45:19
【问题描述】:

我有问题。我有一个 ViewController1 包含一个 tableView.that tableView 创建一个自定义 tableViewCell

-(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];
}

现在我希望用户单击 didSelectItemAtIndexPath 方法中的 collectionView 项打开新的 ViewController2 并将数据传递给 ViewController 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,但我不知道在编程中? 我该怎么办?

【问题讨论】:

  • 所以,如果您在集合视图中选择单元格,它应该推送到第二个视图控制器。你是这个意思吗?
  • 是的..我不知道如何推送到第二个 ViewController

标签: ios objective-c uitableview


【解决方案1】:

实现 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];
    }   

}

【讨论】:

  • 我不能在 didSelectItemAtIndexPath 中调用 self.storyboard?我检查了单元格上的事件点击。这是 Viewcontroller2.h @interface ViewController2 : UITableViewCell
  • 你不使用情节提要吗?我编辑了我的答案。试试这个
  • 是的..我使用 Main.storyboard,我的日程安排:navigationController->VC0 插入 VC1 -> 推送到 VC2。我认为 VC1 是 VC0 的子类,所以它可以调用 self.storyboard。
猜你喜欢
  • 2017-03-16
  • 2017-09-27
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
  • 2013-06-16
  • 1970-01-01
相关资源
最近更新 更多