5

UITableViewController に UISearchDisplayController を実装しました。検索は機能していますが、UISearhDisplayController は標準セルを使用して新しい tableView を作成し、私の tableView はカスタム セルを使用しています。別の問題は、セグエを使用していることです。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

searchResultsTableView のセルはセグエをトリガーしていません。

カスタムセルとセグエが機能している検索結果を表示するにはどうすればよいですか?

これはコードです:

...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView){ 
return [nameFilteredObj count];
} else {
return [sortedObj count];
}}

- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"customCell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.textLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Name"];
 } else {
cell.nameLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Name"];
cell.countryLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Country"];
cell.bottleImageView.image = [UIImage imageNamed:[[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Image"]];
} 
return cell; 
}

//The codes for filtering the results and update of searchResultsTableView (not necessary for this question I think):

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[nameFilteredObj removeAllObjects];

for(NSDictionary *obj in sortedObj)
{
NSString *objName = [obj objectForKey:@"Name"];
NSRange range = [objName rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
    [nameFilteredObj addObject:obj];
}}}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return NO;}
...

インターフェイスとして Storyboard を使用しています。

4

1 に答える 1

-8

実際には非常に簡単ですが、途中で多くの複雑な半作業ソリューションを見つけました。この簡単な部分を使用すると、SearchResultsTableView はなくなります。

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
...
self.searchDisplayController.searchResultsTableView.hidden=YES;
return YES;
}
于 2012-11-04T20:48:31.613 に答える