简体   繁体   English

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

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

I have a custom UITableViewCell that has a CollectionView with many collectionViewCells. 我有一个自定义UITableViewCell,它有一个带有许多collectionViewCells的CollectionView。

Xcode crashes when I click on each CollectionViewCell. 单击每个CollectionViewCell时Xcode崩溃。

Thid code is in the CustomTableViewCell.m file 这些代码位于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;
}

The showFromViewController line crashes. showFromViewController行崩溃了。

Advice? 建议吗?

Your tableviewcell seems to be the collectionviews delegate/data source. 您的tableviewcell似乎是collectviews委托/数据源。 This is generally not a good idea, so everytime you nest table/collectionviews inside cells the viewcontroller managing the outer collection should be the delegate/datasource for both. 这通常不是一个好主意,所以每次在table中嵌入table / collectionviews时,管理外部集合的viewcontroller应该是两者的委托/数据源。 This way your viewcontroller implements the didSelectItemAtIndexPath and can present another VC 这样,您的viewcontroller实现了didSelectItemAtIndexPath,并且可以呈现另一个VC

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

暂无
暂无

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

相关问题 Swift-如何在UITableViewCell内部使用CollectionViewCell打开另一个ViewController - Swift - how to open another viewcontroller with CollectionViewCell inside UITableViewCell 我在CollectionViewCell内部有一个UIButton,它又在TableViewCell内部。如何单击UIButton导航到下一个视图控制器? - I have a UIButton inside a CollectionViewCell which is again inside the TableViewCell.How do i navigate to next view contoller by clicking UIButton? 关闭视图控制器时,在 UITableViewCell 中保存 UICollectionView 的选定状态 - Save selected state of UICollectionView inside UITableViewCell when dismiss the view controller 在自定义TableViewCell内从didSelectItemAt自定义CollectionViewCell更改视图控制器 - change view controller from didSelectItemAt custom CollectionViewCell inside a custom TableViewCell 对collectionviewcell内部的视图进行动画处理 - Animating a view inside a collectionviewcell 如何在UITableViewCell内添加交互式视图控制器? - How can I add an interactive view controller inside of a UITableViewCell? 单击通知时在UITableViewCell中显示相应的内容? - when clicking notification show the corresponding content in UITableViewCell? 点击容器视图后如何保持导航控制器显示? - How to keep the navigation controller after clicking on a container view to show? 如何在子视图控制器中显示转场? - How to show a segue inside a child view controller? 如何在 uitableviewcell 中显示表格 - How to show a table inside a uitableviewcell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM