我有问题。我有一个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,但我不知道在编程中? 我该怎么办?
答案 0 :(得分: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];
}
}