【发布时间】:2014-02-01 05:17:09
【问题描述】:
我正在构建一个应用程序,其中屏幕应该显示一个表格视图,其中表格视图的前两行是两个不同的自定义单元格,其余的是不同的自定义单元格。所以我在我的 cellForRowAtIndexPath 中做了这个: 我的代码:
if (indexPath.row == 0 && !isSearchEnabled) {
FirstRowViewCell *cell;
static NSString *CellIdentifier = @"FirstCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// load a new cell from the nib file
[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
cell = self.firstCell;
//cell.delegate = self;
//cell.indexPath = indexPath;
self.firstCell = nil;
}
return cell;
} else if (indexPath.row == 1 && !isSearchEnabled) {
SecondRowViewCell *cell;
static NSString *CellIdentifier = @"SecondCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// load a new cell from the nib file
[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
cell = self.secondCell;
//cell.delegate = self;
//cell.indexPath = indexPath;
self.secondCell = nil;
}
return cell;
}else {
static NSString *CellIdentifier = @"ContactCell";
ContactTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
// load a new cell from the nib file
cell = self.contactCell;
cell.delegate = self;
cell.indexPath = indexPath;
self.contactCell = nil;
}
return cell;}
但在滚动表格视图时它会滞后。当我在仪器中使用 Time Profiler 检查时,它显示 cellForRowAtIndexPath 尤其是
[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
加载需要很长时间,这会导致延迟。我的问题是,单元格是否被重用,因为即使我们滚动到顶部,上面的行也会为每个单元格执行。请帮助我解决滞后问题。谢谢!
【问题讨论】:
标签: ios iphone objective-c uitableview