Objective c 通过选择以编程方式创建的collectionView的单元格,切换到另一个ViewController
我有一个CollectionView,它是通过编程创建的,现在我想通过选择它的一个单元格切换到另一个CollectionView。到目前为止,我的代码是这样的,但什么都没有发生:Objective c 通过选择以编程方式创建的collectionView的单元格,切换到另一个ViewController,objective-c,uiviewcontroller,uinavigationcontroller,uicollectionview,Objective C,Uiviewcontroller,Uinavigationcontroller,Uicollectionview,我有一个CollectionView,它是通过编程创建的,现在我想通过选择它的一个单元格切换到另一个CollectionView。到目前为止,我的代码是这样的,但什么都没有发生: -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{ NSLog(@"Cell selected"); DetailCell *detailCe
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
NSLog(@"Cell selected");
DetailCell *detailCell = [[DetailCell alloc] init];
[self.navigationController pushViewController:detailCell animated:YES];
}
控制台显示“Cell selected”,因此CollectionView可以识别我的触摸,但应用程序不会切换到其他视图。我已经用自定义类“DetailCell”创建了一个ViewController。我会检查并确保您的self.navigationController不是零。我刚刚解决了这个问题: mainView.m
cView = [[CollectionView alloc]init];
cView.view.frame = CGRectMake(0, 0, 320, 436);
cView.nav = self.navigationController;
[_contentScrollView addSubview:cView.view];
CollectionView.h
@property (nonatomic,weak) UINavigationController *nav;
CollectionView.m
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
DetailCell *detailCell = [[DetailCell alloc] initWithDetails:_pageCategorie and: indexPath];
[_nav pushViewController:detailCell animated:YES];
}
好的,我检查了它,它是零,我如何更改它/如何将它添加到navigationController?My collectionView是在Scrollview中创建的,Scrollview位于导航控制器的根视图控制器中。为什么要将UICollectionView放在UIScrollView中?UICollectionView是UIScrollView的一个子类。我将在线查看关于如何使用集合视图的众多教程之一。据我所知,您遇到了问题,因为您没有按预期使用集合视图。这是一个水平滚动视图,我将许多集合视图放在一起。