0

I have a UITableView with a UISearchBar in a project that uses storyboard.

The search function without problem.

I have the cell linked to a Seague Push to the next view.

If I select a cell, the next view is loaded and everything works perfect.

Everything was perfect until I use UISearchBar, then stops working Segue Push and I can not go to the next view when I select the filtered cell.

What to do? Force segue.

A model of a project at this links:

http://uploaded.to/file/ooohrxnf

//Code for search
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{

[searchData removeAllObjects];

NSArray *group;

for(group in arraynumbers)
{
    NSMutableArray *newGroup = [[NSMutableArray alloc] init];
    NSString *element;

    for(element in group)
    {
        NSRange range = [element rangeOfString:searchString options:NSCaseInsensitiveSearch];

        if (range.length > 0) {
            [newGroup addObject:element];
        }
    }

    if ([newGroup count] > 0) {
        [searchData addObject:newGroup];
    }        
}

onTableData = searchData;

return YES;
}

// Force Segue when UISearchBar isActive
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.searchDisplayController.isActive) {


    NSMutableArray *mutablerray = [searchData objectAtIndex:indexPath.section];        
    number = [mutablerray objectAtIndex:indexPath.row];       
    [self performSegueWithIdentifier:@"detail" sender:self];
    searchBar.text = @"";
}

}

// pickup number when UISearchBar isNotActive and reloadData after Segue
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"detail"])
{
    if (!self.searchDisplayController.isActive) 
    {

        number = [[onTableData objectAtIndex:[[self.tableView indexPathForSelectedRow] section]] objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
    }

    NSLog(@"number: %@", number);
    [segue.destinationViewController setNumber:number];

    [self.tableView reloadData];
}
}
4

1 に答える 1

0

UISearchDisplayController は私にとって非常に新しいものだったので、まったく同じ問題に遭遇し、さまざまなことを試しました。最終的に、tableView を searchDisplayController の searchResultsDelegate として設定しました。

searchDisplayController.searchResultsDelegate = self;

なぜこれがそれを処理したのかはよくわかりません。説明のある人はいますか?

于 2012-05-27T04:15:35.073 に答える