Ios 带搜索显示控制器的UITableView具有缓慢的初始滚动
我有一个带有搜索栏的Ios 带搜索显示控制器的UITableView具有缓慢的初始滚动,ios,uitableview,Ios,Uitableview,我有一个带有搜索栏的UITableView。我使用的是从xib加载的自定义单元格,带有7个UILabels。当我通过搜索栏输入数据时,初始滚动总是很慢。我将尝试向下滚动searchResultsTableView,那里有一个明显的延迟。之后,在表格中滚动是流畅的。滞后仅出现在新搜索的第一个滚动条上 我还在不同的tableview上使用了相同的自定义单元格,并且似乎可以使用相同的cellforrowatinexpath逻辑进行良好的滚动 如何消除searchResultsTableView上的延迟
UITableView
。我使用的是从xib加载的自定义单元格,带有7个UILabels
。当我通过搜索栏输入数据时,初始滚动总是很慢。我将尝试向下滚动searchResultsTableView,那里有一个明显的延迟。之后,在表格中滚动是流畅的。滞后仅出现在新搜索的第一个滚动条上
我还在不同的tableview上使用了相同的自定义单元格,并且似乎可以使用相同的cellforrowatinexpath
逻辑进行良好的滚动
如何消除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中(有一个连接了数据源和委托的tableview)
- (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;
}