Not 100% sure about this, but I don’t think there is a way to set the contents of the UITableView to a “Dynamic Prototype” in the XIB file.
However, you can achieve the same functionality by creating another XIB file called "MyTableViewCell.xib" that contains only UITableViewCell, assigns an identifier to the cell, goes to the file owner, and the same view controller class is set in the identity inspector as xib, and create an IBOutlet in your view controller as follows:
@property (nonatomic, assign) IBOutlet UITableViewCell *customCell;
then in the XIB click “File Owner” and drag the control into the uitableviewcell cell and set the cell output to the “customCell” property.
(This can be made much simpler if you find a button that looks like a play button inside a circle in the lower left corner of the image editor, click on it, and then drag it to this column).
After all this, in cellForRowAtIndexPath, use code similar to this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil]; cell = customCell; }
Hope this makes sense and fits your needs!
starryVere
source share