Reputation: 117
I want to create a generic uitableviewcell which i'll customize by overriding some methods.
There's my parent UITableViewCell : IconTitleGenericTableViewCell
I've designed my cell in a xib file : IconTitleGenericTableViewCell.xib
Now i've subclassed my parent cell with this child class : MyTitleCell
What i want is MyTitleCell to instantiate the designated xib file from it's parent.
I've tried to use
UINib *nib = [UINib nibWithNibName:key bundle:bundle];
[tableView registerNib:nib forCellReuseIdentifier:identifier];
But the cell return in by
MyTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath];
is an IconTitleGenericTableViewCell and not MyTitleCell.
How can i managed to get the same view and outlets link without any xib duplication ?
Upvotes: 2
Views: 1063
Reputation: 19872
Make a nib file independent UIView, make all outlet connections to FileOwner and load your cell using that function:
- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { {
return [super initWithNibName:@"YourXibName" bundle:nil]);
}
Upvotes: 0
Reputation: 9825
Make a nib with a regular UIView
in it with the File's owner as your IconTitleGenericTableViewCell
and in initWithStyle:reuseIdentifier:
load the view from the nib and add it to the cell's content view.
Then register your cells using registerClass:forCellWithReuseIdentifier:
. Any subclass you register will come out as the correct class when dequeued and have the view from the nib added to it's content view.
Upvotes: 2