Swift: How to use “didSelectItemAtIndexPath” in UITableViewController(contains UICollectionView)?

后端 未结 2 593
北荒
北荒 2021-01-15 14:49

I have a UITableViewController, inside the TableViewCell, it\'s a UICollectionView. I want to pass the data from the CollectionV

2条回答
  •  太阳男子
    2021-01-15 15:27

    So, You have not implemented the

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    ...
    }
    

    and

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell  
    

    methods in your second implementation. Also, try putting an invisible button over the collection view cell and assign the tag to be the indexpath of that collectionview cell like this:

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell  
    {
    ....
    myButton.tag = indexpath.item
    }
    

    After this you may either implement a delegate callback from collectionviewcell class to the homepagetableviewcontroller class or push the detail view controller directly by code.

    As far as setting of image in the detail view controller is concerned. You can do it both in viewdidLoad() or viewDidAppear(). Its fine.

提交回复
热议问题