Android Dev Android Dev - 2 months ago 12
Swift Question

How to Display Collection View inside tableview with custom header action like app store in IOS using Swift

I'm an android developer and new to iOS development and want this behaviour

Just like app store i want a list of products to be shown based on its category inside a tableview.

I searched online and found this tutorial

It is showing how to add collection view inside each section which solves my problem of how to show products for categories.

And also i can show category name using this snippet:

Code Snippet :

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return categories[section]
}


But the most important one is i want to show 'View All' at the extreme right of category title row (Just like app store). When user clicks on 'View All' all the products in the category will be displayed in separate page(which i can handle)

How to get this behaviour of showing 'View All' and onTapListener for corresponding category?

Attached image (with arrow marked).
View Image
Anyone please help me in this regard.

Answer

I feel using a collection view make sense instead of tableView here, as you want to have a home page like appstore which has list of categories which are vertically scrollable and each category cell has products/apps which are horizontally scrollable i implement this way:

  1. Create a categoriesCollectionview
  2. categoriesCollectionview holds a an array if categories
  3. inside a each categoryCollectionViewCell feed another horizontally scrolling productsCollectionView
  4. productsCollectionView will hold products if that category

I this will push you to start implementing this. Comment below if you have any doubts.