UITableView NSRangeExcpetion bei reloadData

  • UITableView NSRangeExcpetion bei reloadData

    Hallo,

    ich bin grad beim Entwickeln und verzweifle seit Tagen an einem Fehler und ich kriege es um Himmels willen nicht gebacken....

    Die Fehlermeldung kommt wenn ich versuche in ein TableView die Daten neu zu aktualisieren:


    Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'

    Folgendes passiert in der App:

    Ich lade mittels XML Elemente ein (kriege maximal 100 rein also eine recht überschaubare Menge) diese XML-Elemente werden in Objekte umgewandelt und diese Objekte werden dann in einen MutableArrayList gespeichert:

    Beim reloadData kommt diese Fehlermeldung.

    Quellcode

    1. SeriesSearchParser *ssparser = [[SeriesSearchParser alloc] init];
    2. NSArray *tmpAr = [[NSMutableArray alloc] initWithArray:[ssparser start:urlString]];
    3. tabelle = [[NSMutableArray alloc] initWithArray:tmpAr];
    4. [self.tableView reloadData];



    Die Variable "tabelle" ist mein Sourceelement aus welchem sich die TableView bedient:

    Quellcode

    1. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    2. {
    3. // Return the number of rows in the section.
    4. // Hier funktioniert noch alles!
    5. return tabelle.count;
    6. }
    7. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    8. {
    9. static NSString *CellIdentifier = @"seriesCell";
    10. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    11. if (cell == nil) {
    12. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    13. }
    14. // Configure the cell...
    15. SeriesSearch *tmp = [tabelle objectAtIndex:indexPath.row];
    16. cell.textLabel.text = [tmp SeriesName];
    17. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    18. cell.detailTextLabel.text = [tmp FirstAired];
    19. return cell;
    20. }
    Alles anzeigen




    Der Fehler passiert nur wenn mehr als 3 Einträge in der XML drinnen sind, wenn nur 1 oder zwei funktioniert es.

    Sieht ihr den Fehler?
  • Sorry war eben kurz weg,

    so habe diese beiden Ausgaben eingebaut:

    Quellcode

    1. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    2. {
    3. // Return the number of rows in the section.
    4. NSLog(@"numberOfRowsInSection: %d", self.tabelle.count);
    5. return self.tabelle.count;
    6. }
    7. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    8. {
    9. NSLog(@"cellForRow NORIS: %d", self.tabelle.count); [....]}



    Die Ausgabe ist überraschend den zu dem NSLog in cellForRow kommt es erst gar net:

    Quellcode

    1. 2012-09-15 19:15:37.675 MyApp[17008:c07] numberOfRowsInSection: 100
    2. objc[17008]: EXCEPTIONS: throwing 0x6ec3d10 (object 0x6ec2f60, a NSException)
    3. objc[17008]: EXCEPTIONS: searching through frame [ip=0xc3a85c sp=0xbfffe560] for exception 0x6ec3cf0
    4. objc[17008]: EXCEPTIONS: searching through frame [ip=0x12f8d83 sp=0xbffff300] for exception 0x6ec3cf0
    5. objc[17008]: EXCEPTIONS: unwinding through frame [ip=0xc3a85c sp=0xbfffe560] for exception 0x6ec3cf0
    6. objc[17008]: EXCEPTIONS: unwinding through frame [ip=0x12f8d83 sp=0xbffff300] for exception 0x6ec3cf0
    7. objc[17008]: EXCEPTIONS: handling exception 0x6ec3cf0 at 0x12f8e16
    8. objc[17008]: EXCEPTIONS: rethrowing current exception
    9. objc[17008]: EXCEPTIONS: searching through frame [ip=0x12f8ddf sp=0xbffff300] for exception 0x6ec3cf0
    10. objc[17008]: EXCEPTIONS: terminating
    11. objc[17008]: EXCEPTIONS: searching through frame [ip=0x11b1eed sp=0xbffff290] for exception 0x6ec3cf0
    12. objc[17008]: EXCEPTIONS: catch(id)
    13. objc[17008]: EXCEPTIONS: unwinding through frame [ip=0x11b1eed sp=0xbffff290] for exception 0x6ec3cf0
    14. objc[17008]: EXCEPTIONS: handling exception 0x6ec3cf0 at 0x11b1eff
    15. 2012-09-15 19:15:37.677 MyApp[17008:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
    16. *** First throw call stack:
    17. (0x13c2022 0x11b1cd6 0x13ae644 0x73aea5 0x5471a8 0x4f2688 0x4f4862 0x3a266d 0x3a2167 0x3d19 0xc3a85d 0x1396936 0x13963d7 0x12f9790 0x12f8d84 0x12f8c9b 0x1f957d8 0x1f9588a 0x314626 0x23dd 0x2345)
    18. terminate called throwing an exception
    Alles anzeigen
  • In der Klasse habe ich nur:

    -numberOfSectionsInTableView
    -numberOfRowsInSection
    -cellForRowAtIndexPath
    -didSelectRowAtIndexPath


    von den TableView-Methoden implementiert.

    Im Storyboard habe ich die Höhe der Zelle auf 70 gesetzt, da aber die Zelle erst im cellForRowAtIndexPath generiert wird (und da der Identifier gesetzt wird)
    sollte es sich nicht daran aufhängen.


    Grüß,


    Dave


    €dit:


    @tomekcp


    nein die Cell fängt auch bei 0 an bzw. "indexpath.row" gibt werte ab 0 zurück.
    Wenn ich es mit einem Test durchführe wo ich nur zwei Ergebnisse zurückbekommen funktioniert es.


    Quellcode

    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    2. {
    3. NSLog(@"cellForRow NORIS: %d", self.tabelle.count);
    4. NSLog(@"cellForRowAtIndexPath: %d", indexPath.row);}




    Quellcode

    1. 2012-09-15 19:38:28.122 MyApp[17533:c07] numberOfRowsInSection: 2
    2. 2012-09-15 19:38:28.124 MyApp[17533:c07] cellForRow NORIS: 2
    3. 2012-09-15 19:38:28.125 MyApp[17533:c07] cellForRowAtIndexPath: 0
    4. 2012-09-15 19:38:28.127 MyApp[17533:c07] cellForRow NORIS: 2
    5. 2012-09-15 19:38:28.128 MyApp[17533:c07] cellForRowAtIndexPath: 1

  • Dann setz doch mal einen exception breakpoint und Schau wo er runterknallt. Da scheint ja gewaltig was kaputt zu sein.

    Mitlerweile finde ich das storyboard richtig gut. Alle verwenden es aber keiner weis was er da tut. Grandios....

    Gruß

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)
  • der Debuger bleibt dann bei der stelle mit dem reload stehen:

    Quellcode

    1. [self.tableView reloadData];


    Mit der anderen Höhe im Storyboard wird es nicht zusammenhängen den habe es grad mit einem Standard Cell versucht uns es funktioniert genauso wenig.

    Ich bin mir sicher es ist etwas sehr einfach was auf meine Trotteligkeit zurück zu führen ist.
    Für als Objective-C Anfänger ist es aber schwer rauszufinden woran es scheitert vor allem da es teils funktioniert.

    Grüß,

    Dave
  • Hi DDave,

    wieso versuchtst du nicht meine methode????

    du hast ein Fehler

    Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex: index 3 beyond bounds [0 .. 2]'

    heisst dein array geht von 0-2 du verssuchst auf 3 zuzugreifen!

    seriessearch *tmp = [ tabelle objectatindex:(indexpath.row-1)];

    oder du willst meine hilfe nicht, dann ist es ja ok!
    LG Thomas
  • Also in der Klasse ist nur ein TableView und dieser ist auch nur einem TableView zugeordnet (sonst in der App gibt es auch andere TableViews).

    Zur Zeit gebe ich bei den Sections eine 1 zurück wenn es aber mal läuft ist eine weitere, kleine Section geplant deshalb ist diese Methode bereits implementiert.

    Grüß,

    Dave

    @tomekcp

    weil es zu der Ausführung der von dir genannten Methode gar nicht kommt.
    Habe es aber eben ausprobiert und es ändert nichts, Fehler kommt immer noch.
  • Was hast du noch in der Methode stehen wo du deine Daten aktualisierst? Kann es sein das du davor deine Daten in dein Array schreibst und er noch nicht fertig ist? Ergänzung mach ein Log wenn dein Parser fertig ist und setzt ein breakpoints nach Reload Data! Um zu schauen ob dein Pariser fertig ist.
    LG Thomas