我有UITableView
实施了搜索栏。我正在使用从xib加载的自定义单元格,其中包含7 UILabels
。当我通过搜索栏输入数据时,初始滚动总是很慢。我将尝试向下滚动searchResultsTableView,并且那里有明显的延迟。之后,滚动表格是流动的。滞后仅在第一次滚动新搜索时出现。
我还在不同的tableview上使用了相同的自定义单元格,并且似乎使用相同的cellForRowAtIndexPath
逻辑滚动。
如何使searchResultsTableView上的延迟消失?
以下是一些代码:
//SchoolCell.h
//All labels are hooked up from the SchoolCell.xib to SchoolCell.h
//I haven't touched SchoolCell.m
@property (strong, nonatomic) IBOutlet UILabel *schoolNameLabel;
@property (strong, nonatomic) IBOutlet UILabel *locationLabel;
@property (strong, nonatomic) IBOutlet UILabel *averageGPALabel;
@property (strong, nonatomic) IBOutlet UILabel *averageLabel;
@property (strong, nonatomic) IBOutlet UILabel *tuitionLabel;
@property (strong, nonatomic) IBOutlet UILabel *rankLabel;
在MainViewController.m中(有一个包含数据源和委托的表视图)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
[tableView registerNib:[UINib nibWithNibName:@"SchoolCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:CellIdentifier];
SchoolCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[SchoolCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
RankedSchool *rankedSchool = nil;
UnrankedSchool *unrankedSchool = nil;
if(tableView == self.searchDisplayController.searchResultsTableView){
switch (indexPath.section) {
{case 0:
cell.rankLabel.hidden = NO;
rankedSchool = [self.filteredRankedSchoolsArray objectAtIndex:indexPath.row];
cell.schoolNameLabel.text = rankedSchool.name;
NSString* locationText = [NSString stringWithFormat:@"%@, %@",rankedSchool.city, rankedSchool.state];
cell.locationLabel.text = locationText;
NSString* averageGPAText = [NSString stringWithFormat:@"Average GPA: %@",rankedSchool.gpaExpected];
cell.averageGPALabel.text = averageGPAText;
NSString* averageText = [NSString stringWithFormat:@"Average: %@",rankedSchool.minAvg];
cell.averageLabel.text = averageText;
NSString* tuitionText = [NSString stringWithFormat:@"$%@",rankedSchool.nonresidentTuition];
cell.tuitionLabel.text = tuitionText;
NSString* rankText = [NSString stringWithFormat:@"Rank: %@",rankedSchool.rank];
cell.rankLabel.text = rankText;
break;}
{case 1:
cell.rankLabel.hidden = YES;
unrankedSchool = [self.filteredUnrankedSchoolsArray objectAtIndex:indexPath.row];
cell.schoolNameLabel.text = unrankedSchool.name;
NSString* locationText = [NSString stringWithFormat:@"%@, %@",unrankedSchool.city, unrankedSchool.state];
cell.locationLabel.text = locationText;
NSString* averageGPAText = [NSString stringWithFormat:@"Average GPA: %@",unrankedSchool.gpaExpected];
cell.averageGPALabel.text = averageGPAText;
NSString* averageText = [NSString stringWithFormat:@"Average: %@",unrankedSchool.minAvg];
cell.averageLabel.text = averageText;
NSString* tuitionText = [NSString stringWithFormat:@"$%@",unrankedSchool.nonresidentTuition];
cell.tuitionLabel.text = tuitionText;
break;}
{default:
break;}
}
} else{
//searchBar is firstResponder. User never interacts with tableview, only searchResultsTableView
}
return cell;
}