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];
}

上記のコードは、results>0 の場合に正常に機能します。ただし、foundItems count=0 の場合に問題が発生します。

これを解決するためのアイデアはありません。

4

2 に答える 2

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

numberOfRowsInSection と cellForRowAtIndexPath の両方でセパレーターSyteNone を設定します。

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 に答える