简体   繁体   中英

add property in collection view inside uitableviewcell

I am creating a tableView which has collectionView inside.

what I did : 1. Created a table view inside a controller. 2. created a custom tableViewCell with collectionView inside of that and providing it with tag 3. Created a custom collectionViewcell.

Now i made controller the delegate and datasource for both collectionView and tableView.

Now tableView should have multiple tableViewcells and each tableViewCell has CollectionView

One tableViewCell has one section. Problem :-

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

self.arrayModel = self.SlotsArray[indexPath.section];
}

But here is a catch : lets say my screen size shows two tableViewcell, then all methods of tableCells are called first and then all methods of collectionView are called instead i want that after 1st section of tableViewcell is created , it should call collectionView methods and create it. then go to tableView method make 2nd section and then create its collectionView.

Is there away to do this.

Somewhere i read on net thet i will have to subclass CollectionView and add a property index and then while setting viewcontroller as delegate and datasource , set index also.

But i have created CollectionView By nib and adding it to the tableCell class by "TAG"

self.imageCollectionView = [self.contentView viewWithTag:2511];

Can you tell how can i achieve this?

In your case, you should have one table view, having cells. Each cell will have a collection view inside it.

Number of table view cells will equal to the count of your data-source. As we all know, table view cell will be created one by one and assign each cell a data source which will be used to fill your collection view (which is inside each cell).

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    CategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifierCategory forIndexPath:indexPath];

    NSArray *arrVideos = [parentArray objectAtIndex:indexPath.row];
    [cell setCollectionData:arrVideos];

    return cell;
}

Now, inside that table view cell class, implement setCollectionData method to fill its collection view:

- (void)setCollectionData:(NSArray *)collectionData 
{
    self.arrCollectionData = collectionData;
    [self.yourCollectioView reloadData];
}

Now, each collection cell would be feed from this array:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    VideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifierVideo forIndexPath:indexPath];
    NSDictionary *_video = [self.arrCollectionData objectAtIndex:[indexPath row]];

    // Use this dictionary 

    [cell.lblVideoTitle setText:_video.title];

    ––––––––––
    ––––––––––

    return cell;
}

Refer following image:

在此处输入图片说明

Hope it helps you !!!

You can take a look on this, surely it will help you to implement horizontal scrolling collection view inside uitableviewcell.

https://github.com/ThornTechPublic/HorizontalScrollingCollectionView/blob/master/GithubImages/videoGrid.gif

https://github.com/agusso/ASOXScrollTableViewCell

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