una secretas qué puedo olvido olvide olvida notas nota mis hacer crear contraseña como bloquear apple app abrir iphone ios objective-c uitableview uisearchdisplaycontroller

iphone - secretas - qué hacer si se me olvida la contraseña de una nota en apple



UISearchDisplayController y el bloqueo de celdas del prototipo UITableView (4)

Tengo una configuración de UIViewController en un guión gráfico con una vista de tableview y UISearchDisplayController .

Estoy tratando de usar una célula prototipo personalizada de self.tableview (que está conectada a main tableview en el guión gráfico). Funciona bien si self.tableview ha devuelto al menos 1 celda cuando cargo mi vista, pero si self.tableview no carga una celda (ya que no hay datos), y cargo la UISearchBar y busco, cellForRowAtIndexPath: método se bloquea:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomSearchCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath]; [self configureCell:cell atIndexPath:indexPath]; return cell; } -(void)configureCell:(CustomSearchCell *)cell atIndexPath:(NSIndexPath *)indexPath { User *user = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.nameLabel.text = user.username; }

Errores:

*** Assertion failure in -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:] *** Terminating app due to uncaught exception ''NSInternalInconsistencyException'', reason: ''request for rect at invalid index path (<NSIndexPath: 0x9ef3d00> {length = 2, path = 0 - 0})

My fetchedResultsController parece tener datos (1 sección, 2 filas) en el punto en que se llama al método anterior. Se bloquea en la línea dequeueReusableCellWithIdentifier .

Cualquier punteros / ideas? Debería sacar a la celda del prototipo de la vista de self.tableview , pero supongo que no se creó ninguna en la self.tableview de self.tableview así que esta es la causa?


Este es un tema antiguo, pero si alguien sigue teniendo el mismo problema, para mí estaba relacionado con tener esta línea en viewDidLoad

self.tableView.estimatedRowHeight = 80;

y al mismo tiempo implementando el método delegado heightForRowAtIndexPath con alturas variables en diferentes condiciones

if (indexPath.row == 0) { return 44 + cellTopSpacing; } else { return 44; }

Eliminando la altura de fila estimada se solucionó.


Resolví esto duplicando la célula prototipo en un nuevo xib:

En viewDidLoad:

[self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:@"CustomSearchCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomSearchCell"];

Y se actualizó cellForRowAtIndexPath para usar la vista de tabla del método, no la vista de tabla automática original:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath]; [self configureCell:cell atIndexPath:indexPath]; return cell; }


Si usa un UISearchDisplayController en el método celForRowAtIndexPath, debe usar el método del parámetro tableView y no el puntero de retención del controlador.

prueba con este código

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath];


UISearchDisplayController administra su propia UITableView (tabla filtrada), además de tener su tabla principal. El identificador de celda en la tabla filtrada no coincide con su tabla primaria. También desea obtener la celda no por indexPath ya que ambas tablas pueden ser muy diferentes entre sí con respecto al número de filas, etc.

Así que en lugar de hacer esto:

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

en lugar de hacer esto:

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];