UISearchDisplayController显示父UITableViewController的Header Section

在这里输入图像说明 我正面临与UITableViewController奇怪的问题。 我在UISearchDisplayController中显示search结果。 如果我在search结果中有一些数据,那么它是好的,但是当我有空结果时,它将显示在这个SearchDC后面的UITableView部分。 我有相同的委托和来源为search和正常的表格视图。 参考图像附加后(一个在开始,一个在结束)。我有像下面colde:

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *pstrHeader = [[NSString alloc] init]; if(self.isSearchActivated) { NSInteger count = [self.parrSearchDataSourceKeys count]; if(count > 0) pstrHeader = [pstrHeader stringByAppendingString:[self.parrSearchDataSourceKeys objectAtIndex:section]]; else { pstrHeader = nil; [[[UIAlertView alloc]initWithTitle:@"header of section" message:@"Count is zero" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show]; } } else { NSInteger count = [self.parrDataSourceKeys count]; if(count > 0) pstrHeader = [pstrHeader stringByAppendingString:[self.parrDataSourceKeys objectAtIndex:section]]; else pstrHeader = nil; } return pstrHeader; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //#warning Potentially incomplete method implementation. // Return the number of sections. NSInteger count = 0; if(self.isSearchActivated) { count = [self.parrSearchDataSourceKeys count]; if(count <= 0) { [[[UIAlertView alloc]initWithTitle:@"number of section" message:@"Count is zero" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show]; } } else count = [self.parrDataSourceKeys count]; return count; } 

我有委托和源相同的类,但内部它将处理正常的表视图和search结果表视图不同的地图和数组。

另外我显示如下search结果:

 -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSString *selectedTitle = [searchBar.scopeButtonTitles objectAtIndex: searchBar.selectedScopeButtonIndex]; selectedTitle = [self convertStringToEnglish:selectedTitle]; self.isSearchActivated = YES; FolderInfo* searchFolder = [[FolderInfo alloc] init]; if(self.pmdSearchDataSource != nil) { [self.pmdSearchDataSource removeAllObjects]; } if(self.parrSearchDataSourceKeys != nil) { [self.parrSearchDataSourceKeys removeAllObjects]; } NSString* pstrSearchText = [searchBar text]; NSString* pstrSearchIn = @"Folder"; if([self.pstrWorkspaceId isEqualToString:@"-1"]) { pstrSearchIn = @"Application"; } else if([self.pstrFolderId isEqualToString:@"-1"]) { pstrSearchIn = @"Project"; } self.pmdSearchDataSource = [[NSMutableDictionary alloc] initWithDictionary:[searchFolder GetSearchListForSubElementFor:pstrSearchText InWorkspaceId:self.pstrWorkspaceId InFolderId:self.pstrFolderId forSearchField:selectedTitle In:pstrSearchIn] copyItems:NO ]; NSArray *keys = [[self.pmdSearchDataSource allKeys] sortedArrayUsingSelector:@selector(compare:)]; self.parrSearchDataSourceKeys = [[NSMutableArray alloc] initWithArray:keys]; self.pSearchDC.searchResultsTableView.delegate = self; self.pSearchDC.searchResultsTableView.dataSource = self; [self.view bringSubviewToFront:self.pSearchDC.searchResultsTableView]; [self.pSearchDC.searchResultsTableView reloadData]; } 

如果内部正常的表视图有两个部分可见屏幕上,然后我移动到searchResultDC它将首先显示空白表,但search点击后,当我没有结果,并重新加载searchResultDC tableview它会显示正常的表视图部分behnind这searchResultDC

我提到的职位: UISearchDisplayController后面重新加载UITableView

但是请注意,我在search结果中也需要部分,上面的post中的解决scheme是针对search结果中没有部分的情况。

如果您需要更多信息,请与我们联系。

在这里输入图像说明