I have a UITableViewCell called fatherCell and its nib file,to make code reusable,then I inherit fatherCell by creating childCell without nib file.But I don't know how to make a correct connection from childCell to fatherCell's nib. here is the code:
FatherCell and childCell
@interface FatherCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *titleLabel;
- (IBAction)cellBtnPressed:(id)sender;
@end
@implementation FatherCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.titleLabel.text = @"fatherTitle";
}
- (IBAction)cellBtnPressed:(id)sender
{
NSLog(@"call father method");
}
@end
@interface ChildCell : FatherCell
@end
@implementation ChildCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.titleLabel.text = @"childTitle";
}
- (IBAction)cellBtnPressed:(id)sender
{
NSLog(@"call child method");
}
@end
Then how to call in the UITableViewController? I use following code,but unfortunately I can't get expected result,only called fatherCell's method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"identifier";
ChildCell *cell = (ChildCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"FatherCell" owner:self options:nil] objectAtIndex:0];
}
return cell;
}
Can somebody help me?