Ios 使用UISearch搜索结果下方不必要的空白

Ios 使用UISearch搜索结果下方不必要的空白,ios,objective-c,uitableview,uisearchbar,Ios,Objective C,Uitableview,Uisearchbar,我的应用程序中有一个选项卡,用户可以在其中执行搜索。在用结果填充用户类型关键字和tableView之后,会有很多空行。我已经“清理”了不必要的行(将其改为[UIColor clearColor]),但现在我得到了一个空的空间,问题并没有得到解决。我想要的是,只有一个填充了搜索结果的表,没有空格,没有行(如果有空格,当一个表上只有几个结果时,这很好。但是当有很多结果时,我得到了这个“空”空间,我必须向下滚动才能看到所有结果。在这种情况下,我不希望在最后一个单元格之后出现任何内容)。有一段代码,我用

我的应用程序中有一个选项卡,用户可以在其中执行搜索。在用结果填充用户类型关键字和tableView之后,会有很多空行。我已经“清理”了不必要的行(将其改为
[UIColor clearColor]
),但现在我得到了一个空的空间,问题并没有得到解决。我想要的是,只有一个填充了搜索结果的表,没有空格,没有行(如果有空格,当一个表上只有几个结果时,这很好。但是当有很多结果时,我得到了这个“空”空间,我必须向下滚动才能看到所有结果。在这种情况下,我不希望在最后一个单元格之后出现任何内容)。有一段代码,我用来创建UISearch和tableView,非常简单:

对于UITableView:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    NSLog(@"number of rows is ? %d", self.filteredArray.count);
    return [self.filteredArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSString *_cellText = self.filteredArray[indexPath.row];
    cell.textLabel.text = _cellText;

    return cell;
}
对于UISearch:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    self.filteredArray = [NSMutableArray new];
    self.searchResults = [NSArray new];
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
    self.searchResults = [self._placeOfObjects filteredArrayUsingPredicate:resultPredicate];
    NSLog(@" metod called ");
    NSLog(@"searchResults is %@", self.searchResults);
    //    if (self.searchResults){
    //    _filteredName = ((placeHolder *)(self.searchResults)).name;
    //    NSLog(@"HOLY Grale %@", _filteredName);
    //    }
    //    NSLog(@" What user search is %@", ((placeHolder *)(self.searchResults.name));
    if (self.searchResults.count > 0){
        // _filteredName = ((placeHolder *)(self.searchResults[0])).name;
        for (int i=0; i<[self.searchResults count]; i++) {
            NSLog(@" counto %d", [self.searchResults count]);
            _filteredName = ((PlaceHolder *)(self.searchResults[i])).name;
            [self.filteredArray addObject:_filteredName];
        }
    }
    else {
        NSLog(@"array is empty");
    }
    NSLog(@"HOLY WATER %@", _filteredName );
    NSLog(@" %@ holy array", self.filteredArray);
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    // Tells the table data source to reload when text changes
    [self filterContentForSearchText:searchString scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
    // Tells the table data source to reload when scope bar selection changes
    [self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView;
{
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)];
    footer.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:footer];
}
-(void)filterContentForSearchText:(NSString*)搜索文本范围:(NSString*)范围
{
self.filteredArray=[NSMutableArray new];
self.searchResults=[NSArray new];
NSPredicate*resultPredicate=[NSPredicate predicateWithFormat:@“名称包含[c]@”,搜索文本];
self.searchResults=[self.\u使用predicate:resultPredicate筛选对象的位置];
NSLog(称为“metod”);
NSLog(@“searchResults is%@”,self.searchResults);
//if(self.searchResults){
//_filteredName=((占位符*)(self.searchResults)).name;
//NSLog(@“神圣格拉尔%@”,过滤名称);
//    }
//NSLog(@“什么是用户搜索%@”,((占位符*)(self.searchResults.name));
如果(self.searchResults.count>0){
//_filteredName=((占位符*)(self.searchResults[0])).name;

对于(int i=0;是搜索栏和表格之间的空白?如果是这样,您需要调整这两个UI组件的位置。它位于最后一个单元格下方,保存数据。我猜您没有正确指定表格的维度,或者您将这些组件放在
UIScrollView
上,该视图设置为大于屏幕维度。但是屏幕截图可能更容易看到问题。或者您意外放置了一个额外的表格单元格。问题已解决,谢谢Dino Tw,您是对的(我没有正确设置tableView)