I have a UITableViewController
with static cells in an App. Is there any way I can use default cells in the table view along with subclass cells by code? My tableview has 8 rows and 6 of those rows want to use default cells in the tableview. For the remaining two cells I want to create it by code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
if (cell == nil) {
cell = [[MyCustomCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"MyCustomCell"];
}
return cell;
}
And in the MyCustomCell.m contains,
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
self.myLabel.backgroundColor = [UIColor clearColor];
self.myLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
self.myLabel.textAlignment = NSTextAlignmentCenter;
self.myLabel.text = @"Hi there";
[self.contentView addSubview:self.myLabel];
}
return self;
}
The -tableView:CellForRowAtIndexPath:
method helps to create the custom cells
by code but I have no idea idea how to access the default cells
here if it is possible.