Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView inside UICollectionView handling touches.

Collection view consists of a single row, of horizontally aligned cells, which size is the same size as the collection view's bounds, single cell fills entire screen.

The problem is that the collection view seems to be intercepting all of the pans. How can I forward them to the table so I can also scroll the table vertically.

I want vertical pan to be delivered to the table inside the cell, so it can scroll up and down. I want horizontal pan to be delivered to the collection view, so it can scroll horizontally.

Any ideas? Thanks.

like image 303
foFox Avatar asked Mar 04 '13 01:03

foFox


2 Answers

For UITableView inside CollectionView using storyBoard, please follow these steps:

-Drag CollectionView to UIViewController, drag datasource to UIViewController(don't drag delegate). Add datasource methods inside ViewController.m

-Create Cell:CollectionViewCell class. choose class for Cell in storyBoard to Cell class,specify reuse ID.

-Drag tableView inside collectionCell square. delegate, datasource drag to CollecionCell Square too. Add tableView datasource, delegate inside Cell.m

-Create CellDelegate when implement tableViewDidSelect inside it. Transfer this delegate to UIViewController to perform other action

Sample code: https://github.com/lequysang/github_zip/blob/master/TableViewInCollection.zip

like image 64
LE SANG Avatar answered Sep 20 '22 19:09

LE SANG


Swift2 update - We don't need to do all the above steps. Just making the controller the delegate and datasource of both the tableview and collection view works just fine.

like image 33
Maddiee Avatar answered Sep 21 '22 19:09

Maddiee