2010-11-04 7 views
0

J'ai un viewcontroller avec une plume - qui a une tableview, searchbar et searchdisplaycontroller à l'intérieur.tableView: cellForRowAtIndexPath: ne pas être appelé lors de l'utilisation de la barre de recherche

Le contrôleur de contenu de searchdisplaycontroller, le délégué de résultats, le délégué et la source de données de résultats sont câblés au contrôleur de vue dans IB. Le délégué de la barre de recherche est connecté au contrôleur de vue dans IB. La tableview principale est également câblée au viewcontroller et ses éléments de chargement pendant l'exécution correctement. Tout semble fonctionner à l'exception de resultstableview: il n'est jamais peuplé et la tableView: cellForRowAtIndexPath: ne reçoit jamais d'appel APRÈS que l'utilisateur tape dans la barre de recherche - il est seulement appelé pour remplir la tableview principale.

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

    // Dequeue or create a cell o f the appropriate type. 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

    if (tableView.tag == 2) 
    { 
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

     // Configure the cell. 
     NSHotel *selectedHotel = [[self hotelList] objectAtIndex:[indexPath row]]; 

     //Store the hotel id for use later 
     selectedHotel.id = [indexPath row]; 

     //cell.textLabel.text = [NSString stringWithFormat:@"Catalonia Majorica", indexPath.row]; 
     cell.textLabel.text = [selectedHotel name]; 
    } 
    else if (tableView.tag == 1) 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 

     // Configure the cell...  
     NSAirport *selectedAirport = nil; 

     if (tableView == self.searchDisplayController.searchResultsTableView) 
     { 
      selectedAirport = [self.filteredListContent objectAtIndex:indexPath.row]; 
     } 
     else 
     { 
      selectedAirport = [self.listContent objectAtIndex:indexPath.row]; 
     } 

     //Set the label of the cell formatting the distance from the device 
     cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@ miles", 
           selectedAirport.name, [self formattedStringWithDecimal:selectedAirport.milesFromDevice]]; 

     //Adjust the front of the label 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:12]; 

    } 

    return cell; 
} 

Répondre

1

fixe - il retournait 0 ici:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     if (tableView == self.searchDisplayController.searchResultsTableView) 
     { 
      return [self.filteredListContent count]; 
     } 
     else if (tableView.tag == 1) 
     { 
      return [self.listContent count]; 
     } 
     else if (tableView.tag == 2) 
     { 
      // Return the number of rows in the section. 
      return [[self hotelList] count]; 
     } 

     NSLog(@"The rows in tableview!"); 
     return 0; 
    } 
Questions connexes