InitWithStyle: (UITableViewCellStyle) not being called

Weird thing just started, I am trying to create my own table, but my initWithStyle is not getting called.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

      

My Tablecell looks ok:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        NSLog(@"xx1111");
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

      

How do I try to load the Customcell nib item:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *TFDCustomCell = @"TFDCell";
    TFDCell *cell = (TFDCell *)[tableView dequeueReusableCellWithIdentifier:TFDCustomCell];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TFDCell"
                                                     owner:self options:nil];
        for (id oneObject in nib) if ([oneObject isKindOfClass:[TFDCell class]])
            cell = (TFDCell *)oneObject;
    }

return cell;

}

      

But NSLog(@"xx1111");

doenst appears in my logs. When I set NSLog to 'setSelected' it works "fine"

+3


source to share


3 answers


The solution was simple



-(id)initWithCoder:(NSCoder *)aDecoder
{
    NSLog(@"initWithCoder");

    self = [super initWithCoder: aDecoder];
    if (self)
    {

    }
    return self;
}

      

+13


source


As I know, if you load your view (in the cell of the current case) from the nib method initWithStyle:

, it won't get called. Overload instead awakeFromNib:

to do custom initialization.



+5


source


You are not initializing table cells with initWithStyle , so your custom cell's initWithStyle will not be fired. But awakeFromNib will be called for your dequeueReusableCellWithIdentifier initialization call .

0


source







All Articles