Using a UICollectionView from a UICollectionViewCell

后端 未结 6 1651
感情败类
感情败类 2021-01-13 06:38

I have a custom UICollectionViewCell whose content is also a collection and I would like to use UICollectionView to display its content. Is this possible? How would I accomp

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 07:13

    It isn't possible to add a container view to the UICollectionVIew prototype cell in the storyboard, as BrettThePark mentioned.

    What you can do is create a separate view controller in the storyboard and add this programatically to the view in the UICollectionViewCell subclass you're using in your UICollectionView. This view controller can off course be a UICollectionViewController.

    Example:

    -(void)awakeFromNib 
    {
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                             bundle: nil];
        UIViewController *controller = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyUIViewController"];
    
        [self addSubview:controller.view];
    }
    

提交回复
热议问题