I’m trying to add a ViewController to my TableView cell however it is not showing up when testing.
PhotoLocation is a UIViewController subclass. I have a View Controller created on the StoryBoard with a bunch of UILabels, UITextFields, UISwitch, etc configured on it. PhotoLocation is associated with that StoryBoard View Controller and its Identifier is PhotoLocation.
In a separate controller – UITableViewController, I have a working TableView with cells that are populating with various information, I am trying to add the PhotoLocation VC as a subview of each cell. (Note: PhotoLocation is a freeform sized VC that is of size 210×100).
In my cellForRowAtIndexPath method I’m doing the following:
// snip code above which sets up the cell and performs various other things
PhotoLocation *photoLocation_ = [self.storyboard instantiateViewControllerWithIdentifier:@"PhotoLocation"];
[photoLocation_.view setFrame:CGRectMake(115, 0, 210, 109)];
[cell.contentView addSubview:photoLocation_.view];
return cell;
When I run the app the subview does not show up in the cells. Is there something here I’m missing?
If I understand you correctly, try doing creating a nib file (File–>New File–>User Interface–>View). Delete the “view” and drag a Table View Cell out. Lay it out as you have described in your post. In your tableViewController do:
The reason being, you cannot have 2 “viewControllers” on screen at the same time with the exception of Controllers of Controllers (Tab Bar, Navigation, SplitView). You are trying to put one view controller in another view controller right now.