Error de afirmación para UITableView selectRowAtIndexPath

I feel like this is an issue that requires special attention... my Google-fu is pretty good but I haven't been able to get anything useful.

This is the simplest thing, and yet I can't seem to figure out what the problem is with it.

I have a UITableView. It's a subview that my VC calls _form. I'm using it for styling purposes, not really to display data. It has 2 cells.

On a certain event, I'm trying to select a different cell, using selectRowAtIndexPath:animated:scrollPosition.

When I do this, it SIGABRTS.

Un ejemplo simple:

- (IBAction)submitClicked:(id)sender
{
    [_submit setTitle:@"Wha!?" forState:UIControlStateNormal];
    NSIndexPath *row = [NSIndexPath indexPathWithIndex:0];
    NSLog(@"%d", [[_form indexPathForSelectedRow] row]);
    [_form selectRowAtIndexPath:row animated:YES scrollPosition:YES];
}

The button's title is changed, AND the table prints that the selected row is 0 or 1, but on trying to select the desired cell, it breaks:

2012-03-09 21:57:39.905 <omitted>[16329:207] 0
2012-03-09 21:57:39.908 <omitted>[16329:207] *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewSupport.m:2598
(gdb)

My assumption is that this implies something is wrong with how my table is configured, but I'm not sure what. Selecting the cells in the table normally (clicking it) is working, as indicated by the expected response in my tableView:didSelectRowAtIndexPath. Everything else works fine with how I have this set up, except this.

(Also, I other people replying with extra debug info, not just "(gdb)". How can I get this?)

¡Gracias!

preguntado el 10 de marzo de 12 a las 06:03

1 Respuestas

An indexpath for a tableview cell needs to have both a row and a section. Try creating your index path using the factory method (defined in Adiciones de NSIndexPath UIKit) like this instead:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[_form selectRowAtIndexPath:indexPath animated:YES scrollPosition:YES];

respondido 10 mar '12, 08:03

Thanks, wow that's frustrating. That's what I get for relying too much on what the code hinting tells me. It never suggested that one. >:-( - Liandri

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.