-1

image with comment[![image with out comment]2I have use one tableView. Inside tableViewCell i want to populate a collectionView. I have a static array

Here is my code

var menuImage = ["download.jpeg","download (1).jpeg","download (2).jpeg","download (3).jpeg","download (4).jpeg","download (3).jpeg","download (4).jpeg","download (3).jpeg","download (4).jpeg"]


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menuImage.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:HomeTableViewCell = tableView.dequeueReusableCell(withIdentifier: "HomeTableViewCell", for: indexPath) as! HomeTableViewCell
        // cell.collectionView.reloadData()
        return cell
    }

inside tableViewCell ->

class HomeTableViewCell: UITableViewCell {
    @IBOutlet weak var collectionView: UICollectionView!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
}

and this is the collectionView

extension HomeVC: UICollectionViewDelegate, UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return menuImage.count
    }

    func numberOfSections(in tableView: UITableView) -> Int {
       return  1
    }


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
       let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomeCollectionViewCell", for: indexPath) as! HomeCollectionViewCell
        cell.imgvw.image = UIImage(named: menuImage[indexPath.row])
        cell.profileName.text = menus[indexPath.row]
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        print("Collection view at row \(collectionView.tag) selected index path \(indexPath)")
    }
}

Still the static data is not showing. please help

Gorib Developer
  • 587
  • 2
  • 13
  • 27

2 Answers2

1

I would suggest you to Follow the steps mentioned in this Video Collection View inside TableView cell

Moreover you can refer this link also: Collectionview in tableview cell

Hope this helps.

Issue in Image added

As stated by you , you have added the image directly to Xcode i.e. Drag and Drop,

So do cross check if the Target Member Ship is ticked or not.? If not the please tick that.

Also it is suggested to name the image properly like image1,image2,image3,image4,etc so that it gets detected without any issue.

enter image description here

Edit Link to a demo Project added

You can find a demo of Collection View inside a tableView cell here: Demo of imageCollectionView inside TableViewCell

Abhirajsinh Thakore
  • 1,806
  • 2
  • 13
  • 23
1

If you want to show all images below username than you need to change the Layout. it's not possible in that layout.

so my suggestion is : You display only user details in HomeVC, once any row is tapped, move to new screen and show user details along with all images like instagram user profile.

Edit of your Demo : https://www.dropbox.com/s/v05k2udqa3pu1dd/Demp1.zip?dl=0

Kuldeep
  • 4,466
  • 8
  • 32
  • 59