objective c - iOS - Deleting Rows From UITableView -


before getting problem, must state i've checked other questions regarding problem.

i'm having problems deleting rows uitableview.

my app enables user select contacts , shows names , numbers in uitableview , saves these info in 2 mutable arrays called people , numbers.

this method use deleting cells.

-(void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {  //[tableview beginupdates]; if (editingstyle == uitableviewcelleditingstyledelete) {    //[numbers removeobjectatindex:indexpath.row];    //[people removeobjectatindex:indexpath.row];    [self.tabledata removeobjectatindex:indexpath.row];    [tableview deleterowsatindexpaths:[nsarray arraywithobjects:indexpath, nil] withrowanimation:uitableviewrowanimationright];  } //[tableview endupdates]; [tableview reloaddata];} 

this data setting

#import <uikit/uikit.h> @import addressbook; @import addressbookui;  @interface addedcontacts : uiviewcontroller <uitextfielddelegate, abpeoplepickernavigationcontrollerdelegate, uitableviewdelegate, uitableviewdatasource>{ nsmutablearray* people; nsmutablearray* numbers; iboutlet uitableview *tableview; } @property (strong, nonatomic) iboutlet uitableview *mtv; - (ibaction)addperson:(id)sender; - (ibaction)editbutton:(id)sender; @property (nonatomic, strong) nsmutablearray *tabledata;  @end 

i define tableview iboutlet's properties in beginning of .m file.

-(void)viewdidload{ [super viewdidload]; tableview.delegate = self; tableview.datasource = self;} 

and exception thingy get;

2015-07-14 16:16:06.207 mytestapp[716:607] *** assertion failure in -[uitableview _endcellanimationswithcontext:], /sourcecache/uikit_sim/uikit-2935.137/uitableview.m:1368 2015-07-14 16:16:06.491 mytestapp[716:607] *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of rows in section 0.   number of rows contained in existing section after update (6) must equal number of rows contained in section before update (6),  plus or minus number of rows inserted or deleted section (0 inserted, 1 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).' 

so, did wrong?

i can provide first thrown call stack or more code if required.

more info

-(nsinteger) tableview:(uitableview*) tableview numberofrowsinsection:(nsinteger)section { nsuserdefaults* defaults = [nsuserdefaults standarduserdefaults]; numbers = [[nsmutablearray alloc] initwitharray:[defaults objectforkey:@"numbers"]]; return [numbers count]; }   -(bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath{ return yes; } 

you shouldn't call reloaddata straight after calling deleterowsatindexpaths. might cause animation conflicts may cause of current crash.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -