繁体   English   中英

单击CollectionViewCell INSIDE a UITableViewCell时如何显示视图控制器

[英]How to show view controller when clicking on CollectionViewCell INSIDE a UITableViewCell

我有一个自定义UITableViewCell,它有一个带有许多collectionViewCells的CollectionView。

单击每个CollectionViewCell时Xcode崩溃。

这些代码位于CustomTableViewCell.m文件中

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];

    imageInfo.imageURL = [[NSURL alloc] initFileURLWithPath:[self.fullSizeImagePath objectAtIndex:indexPath.item]];
    imageInfo.referenceRect = self.superview.frame;
    imageInfo.referenceView = self.superview;

    // Setup view controller
    JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                           initWithImageInfo:imageInfo
                                           mode:JTSImageViewControllerMode_Image
                                           backgroundStyle:JTSImageViewControllerBackgroundOption_Scaled];

    // Present the view controller.
    [imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOriginalPosition];
    imageViewer = nil;
}

showFromViewController行崩溃了。

建议吗?

您的tableviewcell似乎是collectviews委托/数据源。 这通常不是一个好主意,所以每次在table中嵌入table / collectionviews时,管理外部集合的viewcontroller应该是两者的委托/数据源。 这样,您的viewcontroller实现了didSelectItemAtIndexPath,并且可以呈现另一个VC

您可以在tableViewCell中添加CollectionViewController而不是CollectionView,这样您就可以呈现模态,并且您的单元格不会直接处理数据源/委托。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM