iphone - NSMutableArray Doesn't remember location of objects -



iphone - NSMutableArray Doesn't remember location of objects -

i created nsmutablearray category. want move objects in array, when moved in table view. category:

- (void)moveobjectfromindex:(nsuinteger)from toindex:(nsuinteger)to { if (to != from) { id obj = [self objectatindex:from]; [self removeobjectatindex:from]; if (to >= [self count]) { [self addobject:obj]; } else { [self insertobject:obj atindex:to]; } } }

and in view controller, call:

- (void)tableview:(uitableview *)table moverowatindexpath:(nsindexpath *)sourceindexpath toindexpath:(nsindexpath *)destinationindexpath { [self.tablearray moveobjectfromindex:[sourceindexpath row] toindex:[destinationindexpath row]]; [self.ammotable reloaddata]; }

but array seems not moving objects within around. reason this? followed tutorial. , should work, if can tell problem please delight me on reason. bunch!

edit

i have tried code below unfortunately doesnt work:

- (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)fromindexpath toindexpath:(nsindexpath *)toindexpath { // fetch object @ row beingness moved nsstring *r = [self.tablearray objectatindex:fromindexpath.row]; // remove original info construction [self.tablearray removeobjectatindex:fromindexpath.row]; // insert object @ target row [self.tablearray insertobject:r atindex:toindexpath.row]; [self.ammotable reloaddata]; }

edit again

cellforrow:

-(uitableviewcell *) tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring * identifier = @"identifier"; self.cell = [tableview dequeuereusablecellwithidentifier:identifier]; handgunammo *handgunammo = [self.tablearray objectatindex:indexpath.row]; self.cell.brandlabel.text = handgunammo.brand; self.cell.caliberlabel.text = handgunammo.caliber; self.cell.numberofroundslabel.text = handgunammo.numberofrounds; homecoming self.cell; }

update

-(void)viewwillappear:(bool)animated{ if (self.context == nil) { self.context = [(rootappdelegate *)[[uiapplication sharedapplication] delegate] managedobjectcontext]; } nsfetchrequest *request = [[nsfetchrequest alloc]init]; nsentitydescription *entity = [nsentitydescription entityforname:@"handgunammo" inmanagedobjectcontext:self.context]; [request setentity:entity]; nserror *error; nsmutablearray *array = [[self.context executefetchrequest:request error:&error] mutablecopy]; [self settablearray:array]; [self.ammotable reloaddata]; [super viewwillappear:yes]; }

//above, load core data.

and im not calling

-(void)viewwilldisappear;

iphone xcode nsmutablearray

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -