我正面临着UITableViewController的奇怪问题。我在UISearchDisplayController中显示搜索结果。如果我在搜索结果中有一些数据,那么它很好,但是当我有空结果时,它将显示位于此SearchDC后面的UITableView部分。我有搜索和普通表视图的相同委托和来源。用帖子附上的参考图像(一个在开头,一个在结尾)。我有如下的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;
}
我有相同的委托和源类,但在内部它将处理普通表视图和搜索结果表视图的不同映射和数组。
我也会显示如下搜索结果:
-(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它将首先显示空白表但是在我没有结果的情况下点击搜索并重新加载searchResultDC tableview它将显示正常表视图的部分behnind这个searchResultDC
我已经提到了帖子: Reloading UITableView behind UISearchDisplayController
但请注意我也需要搜索结果中的部分,上面的帖子中的解决方案是针对搜索结果中没有部分的情况。
如果您需要更多信息,请与我们联系。