简体   繁体   中英

How to add UICollectionView on UITableView Header

How to add UICollectionView to UITableView HeaderView.

Is it possible to add UICollectionView to TableView header?

Following are 2 approaches to solve this requirement:

  1. You can add UIView into a storyboard and define its outlet into controller file and return that view into viewForHeader method of UITableViewDelegate. But this approach will work only for single section.

  2. Another one is creating one .xib file of view which contains collection view in it and return an object of it in viewForHeader delegate method. In this, you can make a separate code for collection view in views file.

Yes it is. Create an instance of a UICollectionView , add it as subview of your header view, add proper constraints to define its size, set its delegate and data source, and you are done.

in viewforheader method. add following code

_xScrollTableViewCell = [ASOXScrollTableViewCell tableView:tableView cellForRowInTableViewIndexPath:indexPath withReusableCellIdentifier:cellIdentifier delegate:self];


    return _xScrollTableViewCell.contentview;

iam using this library : here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM