从UITableView中取消启用了xib文件的单元格

 小牛 发布于 2023-02-12 16:04

在我的UITableViewController子类中,我按如下方式注册我的单元类:

[[self fieldListTableView] registerClass:[MyCellClass class] forCellReuseIdentifier:@"MyCellIdentifier"];

然后,我使用iOS 6中引入的方法将单元格出列:

MyCellClass* cell = (MyCellClass *)[tableView dequeueReusableCellWithIdentifier:@"MyCellIdentifier" forIndexPath:indexPath];

但是,单元格的xib文件似乎缺失了.当我po cell在lldb中运行时,我得到一个有效的单元格对象.然后,当我尝试时po [cell myLabelOutlet],我得到了nil回应.

我是否也需要注册XIB文件?

1 个回答
  • 要从xib文件加载单元格,您必须使用registerNib:而不是使用 它来注册它registerClass:.例:

    [self.fieldListTableView registerNib:[UINib nibWithNibName:@"MyCellClass" bundle:nil]
      forCellReuseIdentifier:@"MyCellIdentifier"];
    

    2023-02-12 16:06 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有