我要与数据源中的所有数据加载搜索显示控制器的表视图用户开始搜索前前SearchDisplayController的数据显示。可以开始搜索
我用
[self.searchDisplayController.searchResultsTableView reloadData];
在viewDidLoad中,但UITableViewDataSource委托方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
不会被调用。我的桌子保持空着。 我手动填充数据源重新加载表视图之前(和在调试模式下验证了这一点),所以有数据来填充细胞。
我知道我能做到这一点使用另一个表视图,并在视觉上达到完全相同的结果,但我想知道,如果只搜索显示控制器的表视图可以使用。
代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
static NSString *cellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSString *category = [searchResults objectAtIndex:[indexPath row]];
cell.textLabel.text = category;
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
return cell;
}
查看cellForRowAtIndexPath的代码: –
检查您的搜索结果为空或不是 –