[英]pass data from uicollectionview in custom tablecell to viewcontroller
我有个问题。 我有一个包含一个tableView的ViewController1。那个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,但是在编程中我不知道吗? 我能怎么做?
实现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];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.