yaniki
yaniki

Reputation: 1

No visible @interface for 'UIViewController' declares the selector initWithStyle:reuseIdentifier:

I instantiate a UITableView in a UIViewController when the view is loaded as :

table = [[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y + hauteurFavorisCell, self.view.frame.size.width, self.view.frame.size.height-hauteurFavorisCell-hauteurNavigationBar)];

[table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"DetailsFavoris"];
table.delegate = self;
table.dataSource = self;
table.hidden = YES;
[self.view addSubview:table];

The problem is that I want the cell to have style : UITableViewCellStyleValue1. Because the cells are create with the method initWithStyle: UITableViewCellStyleDefault. I can't use dequeueReusableCellWithIdentifier:CellIdentifier. My code is thus :

static NSString *CellIdentifier = @"DetailsFavoris";

UITableViewCell *cell ;//= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}

...

return cell;

But I would like to reuse the cells to be more efficient. I wrote down :

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    // ignore the style argument, use our own to override
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
    if (self) {
        // If you need any further customization
    }
    return self;
}

But I got an error : No visible @interface for 'UIViewController' declares the selector initWithStyle:reuseIdentifier:.

What am I doing wrong? I checked on other answers but I found nothing.

Upvotes: 0

Views: 2353

Answers (1)

skywinder
skywinder

Reputation: 21436

Move this code

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    // ignore the style argument, use our own to override
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
    if (self) {
        // If you need any further customization
    }
    return self;
}

To your UITableViewCell subclass. Because this method related to UITableViewCell class, not to UIViewController.

Upvotes: 1

Related Questions