Reputation: 12617
I want to use CustomTableViewCell.xib in several classes. But file's owner is only one. I don't want to clone CustomTableViewCell.xib to CustomTableViewCell2.xib. How do I solve the issue?
Upvotes: 0
Views: 183
Reputation: 372
Similar situation that could use some clarity.
I have 1 XIB file that contains 1 view (a UITableViewCell
) that I'd like to use with several different sub-classes of type UITableViewCell
.
I have created a sub-class of UITableViewCell
called ParentTableViewCell
. Here is the init...
- (id)init
{
ParentTableViewCell *customCell = nil;
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"CustomTVCell" owner:self options:NULL];
for(UIView *aView in nibContents) {
if ([aView isKindOfClass:[UITableViewCell class]]) customCell = (ParentTableViewCell *)aView;
}
return customCell;
}
As you can see, I simply look into the XIB and fetch the custom UITableViewCell
.
Now, if I sub-class the ParentTableViewCell
class as ChildTableViewCell
, I can load the cell into a table fine, but none of my methods in ChildTableViewCell
are available because the cell is seen as ParentTableViewCell
. The class of the UITableViewCell
in the XIB is set to ParentTableViewCell
, and that seems to trump any sub-classing downstream.
Ideas?
Upvotes: 0
Reputation: 119292
If you are using outlets or actions from your other classes in the nib file then you could gather all these into a superclass (which would itself be a subclass of whatever it is your multiple classes currently inherit from, presumably a UITableViewController in this case) and have your other classes inherit from that (and make the files owner an instance of the superclass).
You would then override these methods as necessary in each of your table view controllers.
Upvotes: 1