Uitableview 对于';没有可见的@界面;UIViewController';声明选择器initWithStyle:reuseIdentifier:
当视图加载为以下内容时,我在UIViewController中实例化UITableView:Uitableview 对于';没有可见的@界面;UIViewController';声明选择器initWithStyle:reuseIdentifier:,uitableview,uiviewcontroller,initwithstyle,Uitableview,Uiviewcontroller,Initwithstyle,当视图加载为以下内容时,我在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-hau
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];
问题是我希望单元格的样式为:UITableViewCellStyleValue1。因为单元格是使用initWithStyle:UITableViewCellStyleDefault方法创建的。我无法使用dequeueReusableCellWithIdentifier:CellIdentifier。因此,我的代码是:
静态NSString*CellIdentifier=@“DetailsFavoris”
但我想重复使用这些电池,以提高效率。我写下:
- (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;
}
但是我得到了一个错误:“UIViewController”没有可见的@interface声明选择器initWithStyle:reuseIdentifier:
我做错了什么?我查看了其他答案,但什么也没找到。移动此代码
- (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;
}
到您的
UITableViewCell
子类。因为此方法与UITableViewCell
类相关,而不是与UIViewController
相关,您在哪里实现了initWithStyle:…
?该错误表明您是在UIViewController的子类而不是UITableViewCell的子类中执行此操作。事实上,我是在UIViewController的子类中编写的。当我在ViewDidLoad中实例化UItableView“表”时,它会自动创建具有默认样式的单元格。那么我应该在哪里写initWithStyle方法呢?谢谢!我为我的单元格创建了一个UITableViewCell子类,现在它可以工作了。@yaniki所以,如果问题解决了,你可以接受我的答案;)
- (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;
}