1

使用 UISearchDisplayController 我发现了以下问题,如在此 URL上传的图像中所示。

行的默认高度是 74,但是当结果为零时,我不会发生什么,但会出现多条分隔线。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
     return 74;
}

   -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self performSelectorInBackground:@selector(loadMySearchObjectsInBackground) withObject:nil];  
    return NO;
}

- (void) loadMySearchObjectsInBackground{
    NSString *searchStr=self.searchDisplayController.searchBar.text;
    NSArray *foundItems;
    .....Code to fetch Result from Server.......
    [self.searchDisplayController.searchResultsTableView reloadData];
}

当结果> 0 时,上面的代码可以正常工作。但是当 foundItems count=0 时会导致问题。

任何想法都可以解决这个问题。

4

2 回答 2

2
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
   if ([self.searchDataArray count] == 0) needSeparateCell = NO;
   else needSeparateCell = YES:
}

在 numberOfRowsInSection 和 cellForRowAtIndexPath 中设置 separatorSyteNone

if (tableView == self.searchDisplayController.searchResultsTableView){
    if(!needSeparateCell) {
        [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    } else {
        [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    }
}
于 2013-01-27T20:49:59.893 回答
2

如果您不需要 tableFooterView,有一种非常干净的方法可以实现这一点。

self.searchDisplayController.searchResultsTableView.tableFooterView = [UIView new];

这将删除最后一个单元格下方的所有分隔符。因此,如果您的 tableView 为空,则根本没有分隔线。

它对我来说适用于任何类型的 UITableView。

于 2015-01-14T22:30:16.540 回答