uitableview - XCODE TableView with multiple sections and delegate datasource from array of arrays - can't delete row without error? -


i have tableview multiple sections that's got delegate data source links array of arrays. each array within array of arrays it's own table view section. have loading correctly , have edit button enabled when try , delete app crashes following error.

* terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of sections. number of sections contained in table view after update (9) must equal number of sections contained in table view before update (10), plus or minus number of sections inserted or deleted (0 inserted, 0 deleted).'

now not deleting section confused, here sample of code. have searched forum extensively can't find out have done wrong.

here code:

// calculate how many sections in table view array or arrays

  • (nsinteger) numberofsectionsintableview:(uitableview *)tableview{

    appdelegate *delegate = [[uiapplication sharedapplication]delegate];

    nsinteger sections = [delegate.packing.packinglistarray count];

    return sections; }

// load array , extract count of items each section

  • (nsinteger) tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{

    // each array within array of array count items appdelegate *delegate = [[uiapplication sharedapplication]delegate]; nsarray *sectioncontents = [delegate.packing.packinglistarray objectatindex:section]; nsinteger rows = [sectioncontents count];

    return rows; }

// load list table view

  • (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {

    // set cell identifier - using id field thats been set in interface builder static nsstring *cellidentifier = @"destinationcell";

    // re-use existing cell? uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; // if no reusabled cells create new 1 if (cell == nil){ cell = [[uitableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; }

    // add relevant packing list array array of arrays appdelegate *delegate = [[uiapplication sharedapplication]delegate]; nsarray *sectioncontents = [delegate.packing.packinglistarray objectatindex:[indexpath section]]; nsstring *contentforthisrow = [sectioncontents objectatindex:[indexpath row]];

    cell.textlabel.text = contentforthisrow;

    // return formatted cell text needs display in row return cell; }

// delete row table , update data source array

  • (void) tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle) editingstyle forrowatindexpath:(nsindexpath *) indexpath {

    if (editingstyle ==uitableviewcelleditingstyledelete) {

    [tableview beginupdates];  // delete item array appdelegate *delegate = [[uiapplication sharedapplication]delegate]; [delegate.packing.packinglistarray  removeobjectatindex:indexpath.row];   // delete row table view [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];  [tableview endupdates]; 

    }

}

i have feeling perhaps complication of array of arrays creating multiple sections there mus someway of doing this?

any appreciated i've been looking @ same code hours.

i managed resolve issue, there couple of problems in end. due way trying remove item array or arrays. code should have used this:

appdelegate *delegate = [[uiapplication sharedapplication]delegate]; [[delegate.packing.packinglistarray objectatindex:indexpath.section] removeobjectatindex:indexpath.row]; 

i had issue way had arrays defined built plist although set nsmutablearray being converted nsarray. @ end of statement included.

........mutablecopy];

all problems resolved :)


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -