无法在 UITableViewCell 中注册 UITableView 的委托和数据源

问题描述

它说

从不兼容分配给“id _Nullable” 输入'ChildTableViewCell *__strong'

如果我在自定义 UITableViewCell 中实现 UITableView 单元格有什么错误吗?

  1. 所以首先在 MainViewController 中,使用具有 MainViewUITableView

  2. MainViewController中,尤其是在ViewDidLoad中,我注册self.mainView.tableView.delegate = self;self.mainView.dataSource = self;

  3. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 我有这个:

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

if ([self.filteredCategoriesAllListLocalDataArray count] > 0) {
    static Nsstring *cellID = @"ChildTableViewCell";
    
    ChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if(nil == cell) {
        cell = [[ChildTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                               reuseIdentifier:cellID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    
    CategoryModel *currentCategory = [self.filteredCategoriesAllListLocalDataArray objectAtIndex:indexPath.section];
    ChildModel *currentChildData = [currentCategory.childModelArray objectAtIndex:indexPath.row];
    NSLog(@"================== %@",currentChildData.nameString);
    cell.childData = currentChildData;
    [cell initializeChildTableView];
    
    cell.clipsToBounds = YES;
    return cell;
}

   UITableViewCell *cell = [[UITableViewCell alloc] init];
   return cell; 
}
  1. 然后在 ChildTableViewCell 我有这个:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(Nsstring *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f,0.0f,CGRectGetWidth([UIScreen
mainScreen].bounds),CGRectGetHeight(self.contentView.frame))style:UITableViewStyleGrouped];
    self.tableView.showsverticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.scrollEnabled = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.contentView addSubview:self.tableView];
}
    
   return self;
}

但在第 4 步中,收到此错误消息:

从不兼容分配给“id _Nullable” 输入'ChildTableViewCell *__strong'

我在 UItableViewCell 中使用 UITableView 是因为想要使用自定义数据制作 UITableView 树级别,我一直在搜索 UITableView 多级别的所有参考,但它根本没有帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)