简体   繁体   English

'UIViewController'没有可见的@interface声明选择器initWithStyle:reuseIdentifier:

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

I instantiate a UITableView in a UIViewController when the view is loaded as : 当视图加载为时,我在UIViewController中实例化UITableView:

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. 问题是我希望单元格具有样式:UITableViewCellStyleValue1。 Because the cells are create with the method initWithStyle: UITableViewCellStyleDefault. 因为单元格是使用initWithStyle方法创建的:UITableViewCellStyleDefault。 I can't use dequeueReusableCellWithIdentifier:CellIdentifier. 我不能使用dequeueReusableCellWithIdentifier:CellIdentifier。 My code is thus : 因此,我的代码是:

static NSString *CellIdentifier = @"DetailsFavoris"; 静态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:. 但是我遇到一个错误:“ UIViewController”没有可见的@interface声明选择器initWithStyle:reuseIdentifier:。

What am I doing wrong? 我究竟做错了什么? I checked on other answers but I found nothing. 我检查了其他答案,但一无所获。

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. 到您的UITableViewCell子类。 Because this method related to UITableViewCell class, not to UIViewController . 因为此方法与UITableViewCell类相关,所以与UIViewController不相关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS自定义tableView:'XYZCustomCell'的不可见@interface声明选择器'initWithStyle:reuseIdentifier:' - Ios custom tableView : No visible @interface for 'XYZCustomCell' declares the selector 'initWithStyle:reuseIdentifier:' 'UITableView'的@interface声明选择器'initWithStyle:reuseIdentifiers - no @interface for 'UITableView' declares the selector 'initWithStyle:reuseIdentifiers 'UITableView'的可见@interface没有声明选择器 - No visible @interface for 'UITableView' declares the selector 没有可见的@interface'PhotosTableViewController'声明选择器'viewWithImageName' - No visible @interface 'PhotosTableViewController' declares the selector 'viewWithImageName' 'UITableView'的可见@interface没有声明选择器'setShowsUserLocation:' - No visible @interface for 'UITableView' declares the selector 'setShowsUserLocation:' “ UITableView”没有可见的@interface声明选择器“ cellForRowAtIndexPath:” - no visible @interface for “UITableView” declares the selector “cellForRowAtIndexPath:” 没有“ ToDoListTableViewController”的可见接口声明选择器“ configureCell:atIndexPath:” - No visible interface for 'ToDoListTableViewController' declares the selector 'configureCell: atIndexPath:' 没有可见的UITableViewController接口声明选择器ReloadData - No visible interface for UITableViewController declares the selector ReloadData 'NSMutableArray'没有可见的@interface声明选择器'addUtilityButtonWithColor:icon:' - No visible @interface for 'NSMutableArray' declares the selector 'addUtilityButtonWithColor:icon:' 'UITableViewCell'的可见@interface没有声明选择器'dequeueReusableCellWithIdentifier:' - No visible @interface for 'UITableViewCell' declares the selector 'dequeueReusableCellWithIdentifier:'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM