I figured out by my self, the thing is in my case not to use UICollectionViewLayout
(CustomLayout) use layout Flow
and add the collectionView
inside tableView
like this:

Then in every row of tableView
delegate the collectionView
.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
cell.collectionView.delegate = self
cell.collectionView.dataSource = self
cell.collectionView.tag = indexPath.row
cell.tag = 100 + indexPath.row;
return cell;
}
After delegate, the method collectionView:sizeForItemAtIndexPath
is called, on this method you must to calculate width or height retrieving data using indexPath
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
//Calculation of width based on indexPath
//...
return CGSizeMake(width, 89)
}
Finally for making the scroll uniform for all the cells at the same time use the method scrollViewDidScroll
. Check this post: Horizontally scroll ALL rows of UICollectionView together
func scrollViewDidScroll(scrollView: UIScrollView) {
var ret: Bool = false;
if (self.lastContentOffset > scrollView.contentOffset.x)
{
ret = true;
}
else if (self.lastContentOffset < scrollView.contentOffset.x)
{
ret = true;
}
if(scrollView.isKindOfClass(UICollectionView) && ret)
{
self.lastContentOffset = scrollView.contentOffset.x;
for var i = 0; i < data.count; i++
{
let cell = self.view.viewWithTag(100 + i) as? ChannelTableViewCell;
if(cell != nil)
{
let collectionCell: UICollectionView? = cell?.collectionView;
if(collectionCell != nil)
{
collectionCell!.contentOffset = scrollView.contentOffset;
}
}
}
}
}