0

So I am trying to display horizontally scrollable collection view inside tableviewcell. the code i am using is

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UICollectionViewController *cv = [self.storyboard instantiateViewControllerWithIdentifier:@"collectionViewID"];
cv.view.frame = cell.contentView.bounds;
[self addChildViewController:cv];
[cell.contentView addSubview:cv.view];
[cv didMoveToParentViewController:self];  
return cell; 
}

I am getting error: Object can not be nil. I'd appreciate if someone can help me out understanding the error.

2 Answers 2

3

I have done this in my app.

I found it much easier to subclass UITableViewCell. The I could put all the UICollectionView setup and the UICollectionView datasource and delegate inside the code for the cell.

I then provided one public property of type NSArray which I pass into the cell. The cell then uses this array as the datasource for the UICollectionView that it owns itself.

Made it a lot easier to manage.

Sign up to request clarification or add additional context in comments.

Comments

0

check your UICollectionViewControlle's attribute inspector for identifier value {collectionViewID}

EDIT [self addChildViewController:cv]; --> I think you want to add cv to the cell, isn't you?

2 Comments

then why self isn't you want [cell addChildViewController:cv];
I'm getting error "no visible @interface for UIView declares addchildviewcontrolelr..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.