UITableViewCell automatisch verschieben

  • UITableViewCell automatisch verschieben

    Hallo

    kennt einer von euch eine Möglichkeit wie man eine UITableViewCell von einer Section zu einer anderen Section animiert verschieben kann (automatisch, ohne zutun des Benutzers)?


    Ich habe schon alles versucht bei Google aber nichts brauchbare gefunden...



    Gruß JeyBe
  • hallo

    erstmal danke für eure Hilfe. Mit der Methode habe ich es schon versucht:

    Quellcode

    1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    2. NSIndexPath *newIndexPath;
    3. if (indexPath.section == 0) {
    4. newIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:1];
    5. }
    6. else{
    7. newIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    8. }
    9. [self.tableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
    10. }
    Alles anzeigen


    Doch leider stürtzt die Anwendung immer ab wenn sie an diese Stelle kommt.
    reason: 'attempt to move index path (<NSIndexPath 0x1d840210> 2 indexes [1, 1]) to index path (<NSIndexPath 0x1d83f930> 2 indexes [0, 1]) that does not exist - there are only 1 rows in section 0 after the update'
    muss ich erst die Zelle erst neu hinzufügen? Wenn Ja wie macht man das am besten?

    Grub JeyBe
  • Nein aber du solltest die Zelle auch an die entsprechende Row setzen. Wenn z.B. in Section 1 bisher nur 0 Einträge drin sind, dann kannst du die Zelle nicht an Row 1 einfügen. Dann must du sie auch an Row 0 einfügen.

    Gruß

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)
  • Danke für den Tipp. Innerhalb einer Section funktioniert das auch wunderbar. Doch wenn ich eine Zeile in eine andere Section verschieben will stürzt die App wieder ab.
    Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (1 moved in, 0 moved out).
    wie erkläre ich meinen TableView nun die neue Anzahl der Zeilen und Section?

    Gruß Marvin