【发布时间】:2015-12-23 12:59:58
【问题描述】:
一开始我有这个代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DropDownTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DropDownTableViewCell"];
if (!cell) {
NSArray *topLevelObjects =
[[NSBundle mainBundle] loadNibNamed:@"DropDownView"
owner:self
options:nil];
for (DropDownTableViewCell *object in topLevelObjects) {
if ([object class] == [DropDownTableViewCell class]) {
cell = object;
break;
}
}
NSAssert(cell, @"Cell must not be nil");
}
cell.nameLabel.text = [self.dataSource buttonDownPicker:self stringForRowAtIndexPath:indexPath];
return cell;
}
当我显示 tableView 和 tableView 单元格开始从 nib 加载时,我的 UI 冻结了几秒钟(由于从 nib 加载每个显示的单元格)。这可以通过提前从 nib 加载单元格来解决:
- (void)awakeFromNib {
DropDownTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"DropDownView" owner:self options:nil] objectAtIndex:0];
}
但是这种方式看起来很“hacky”。有没有更合适的解决方案?
根据给出的答案编辑:
我尝试使用 registerNib forCellIdentifier 但它没有加载笔尖,它只是用标识符绑定笔尖,并且在第一次出现 tableView 时所有单元格导致将笔尖加载到内存
【问题讨论】:
标签: ios objective-c uitableview