ios5 uitableview xcode4.2 uisearchdisplaycontroller

ios5 - IOS 5 UISearchDisplayController crash



uitableview xcode4.2 (4)

De hecho, es un error difícil de rastrear, parece que cada vez que haces una búsqueda se crea una nueva vista de tabla. Lo que significa que el registro de su celda debe sacarse de ViewDidLoad ya que esto solo funcionará para la primera búsqueda. En su lugar, utilice el siguiente método de delegado para realizar el registro y la personalización de celdas:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { [self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:@"YOURCELLNIB" bundle:nil] forCellReuseIdentifier:@"YOURCELLID"]; self.searchDisplayController.searchResultsTableView.separatorColor = [UIColor clearColor]; }

Estoy implementando un UITableView con UISearchDisplayController en xcode 4.2. UITableView y UISearchDisplayController se crean en StoryBoard. Configuré el identificador de celda (SampleCell) para UITableView y accedo a él como

cell = [tableView dequeueReusableCellWithIdentifier:@"SampleCell"];

UItableView está funcionando bien. Pero una vez que trato de buscar, la aplicación falla con el siguiente error.

*** Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-11-09 22:22:16.058 SampleApp[14362:fb03] *** Terminating app due to uncaught exception ''NSInternalInconsistencyException'', reason: ''UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:''

Supongo que necesito configurar el identificador de celda para self.searchDisplayController.searchResultsTableView cell. Pero no sé cómo. Gracias de antemano por cualquier ayuda. =)


Puedes en

- (void)searchDisplayController:(UISearchDisplayController *)searchDisplayController didLoadSearchResultsTableView:(UITableView *)searchResultsTableView

hacer

[searchResultsTableView registerNib:[UINib nibWithNibName:@"someNibName" bundle:nil] forCellReuseIdentifier:@"yourReuseId"];

Entonces eres capaz de usar en

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

lo normal

[tableView dequeueReusableCellWithIdentifier:


Utilice [self.tableView dequeue...] , no [tableView dequeue...] .

La celda que está intentando sacar de la cola está vinculada a la tableView del controlador de su vista principal en el guión gráfico, NO a la nueva tableView creada por tableView (que no tiene ningún identificador de celda vinculado). Si acaba de tableView mensaje " tableView ", su mensaje de salida de la cola se dirige a la tableView searchDisplayController''s ya que eso fue lo que se pasó al método cellForRowAtIndexPath: ...

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CellId"]; // do your thing return cell; }


(La respuesta que recomienda el uso de self.tableview depende de otra vista de tabla. Esta es la solución más limpia y se puede usar incluso si el controlador de búsqueda se usa solo).

Debe registrar las celdas en el UITableView de UISearchDisplayController. La mejor manera de hacerlo es registrar las celdas cuando se carga esa vista de tabla.

UISearchDisplayDelegate tiene un método que le notifica cuando se carga la vista de tabla, al igual que viewDidLoad pero para la vista de tabla de búsqueda.

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView { [tableView registerNib:[UINib nibWithNibName:@"MyCellNib" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyCellIdentifier"]; }