在我的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文件?
要从xib文件加载单元格,您必须使用registerNib:
而不是使用
它来注册它registerClass:
.例:
[self.fieldListTableView registerNib:[UINib nibWithNibName:@"MyCellClass" bundle:nil] forCellReuseIdentifier:@"MyCellIdentifier"];