2012-07-03 4 views
0

Никогда не вызывается, когда ячейка поиска таблицы сливаютпанель поиска и поиска контроллер дисплея с Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"Show Detail"]) 
    { 
     Player *player = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]]; 
     [segue.destinationViewController setPlayer:player]; 
    } 
} 

Это фильтрует список правильно, но prepareForSegue никогда не вызывается, когда сливают ячейка поиска таблицы.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Player Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    if (tableView == self.tableView) 
    { 
     // normal table view population 
     Player *player = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
     cell.textLabel.text = [[NSString alloc] initWithFormat:@"#%@ %@ %@", player.number, player.firstName, player.lastName]; 
     cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%@", player.position]; 
     [cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:@"playerplaceholder.jpg"]]; 

    } 
    else if(tableView == self.searchDisplayController.searchResultsTableView) 
    { 
     // search view population 
     Player *player = [self.filteredFetchedResultsController objectAtIndexPath:indexPath]; 
     cell.textLabel.text = [[NSString alloc] initWithFormat:@"#%@ %@ %@", player.number, player.firstName, player.lastName]; 
     cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%@", player.position]; 
     [cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:@"playerplaceholder.jpg"]]; 

    } 

    return cell; 
} 

ответ

1

вам нужно поставить IF, что проверить, если поиск есть результаты. , как в этом коде:

if ([[segue identifier]isEqualToString:@"ShowDetails"]) 
    { 
     ShowDetailsViewController *sdvc = (ShowDetailsViewController *)[segue destinationViewController]; 
     NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow]; 

     Books *selectedBooks = nil; 
     if(self.searchDisplayController.active) 
      selectedBooks = (Books *)[[self searchResults]objectAtIndex:[[[[self searchDisplayController]searchResultsTableView]indexPathForSelectedRow]row]]; 
     else 
      selectedBooks = (Books *)[[self fetchResultsController] objectAtIndexPath:indexPath]; 

     sdvc.currentBooks = selectedBooks; 
    } 
Смежные вопросы