微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法在 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 举报,一经查实,本站将立刻删除。