How to set File's Owner to a custom UITabelViewCell loaded from nib?

372 views Asked by At

I have a custom UITableViewCell loaded from a xib file and instantiated with a view controller as its owner:

- (void)viewDidLoad {
    ...
    UINib *templateCellNib = [UINib nibWithNibName:@"TableViewCell" bundle:nil];
    UITableViewCell *_templateCell = [[templateCellNib instantiateWithOwner:self options:nil] firstObject];
    [self.tableView registerNib:templateCellNib forCellReuseIdentifier:_templateCell.reuseIdentifier];
}

Everything works fine, but File's Owner is null so I can't get access to my view controller from the inside of TableViewCell implementation:

@interface TableViewCell ()

// File's Owner placeholder outlet
@property (weak, nonatomic) IBOutlet TableViewController *fileOwner;

@end

- (void)setUpCell {
    ...
    NSLog(@"File's Owner: %@", self.fileOwner); // outputs "File's Owner: (null)"
}

@end

Why is the File's Owner property not set? And is there any way to wire up a view controller to the TableViewCell nib?

0

There are 0 answers