ios - index 2 beyond bounds exception while trying to fetch record from core data -
i have segmentedcontrol button , table view below segmentedcontrol.
in viewdidload method, im fetching values core data , populating array follows,
nserror *error = nil; apirequest *apirequest = [[apirequest alloc]init]; [apirequest showpendingdata]; nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext]; nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"pendingshipmentdetails"]; self.devices = [[managedobjectcontext executefetchrequest:fetchrequest error:nil] mutablecopy]; nsentitydescription *entity = [nsentitydescription entityforname:@"pendingshipmentdetails" inmanagedobjectcontext:managedobjectcontext]; [fetchrequest setentity:entity]; nsarray *fetchedobjects = [managedobjectcontext executefetchrequest:fetchrequest error:&error]; shipmentreferencenumberarray = [[nsmutablearray alloc]init]; (nsmanagedobjectcontext * info in fetchedobjects) { [shipmentreferencenumberarray addobject:[info valueforkey:@"shipmentno"]]; }
in handleselection method, im handling button clicks follow
- (void)handleselection:(id)sender { uisegmentedcontrol *segmentcontrol = (uisegmentedcontrol *) sender; nsinteger selectedsegment = segmentcontrol.selectedsegmentindex; if (selectedsegment == 0) { //toggle correct view visible [self.myorderstableview sethidden:no]; [self.completedorderstableview sethidden:yes]; nslog(@"pending"); } else { //toggle correct view visible [self.completedorderstableview sethidden:no]; [self.myorderstableview sethidden:yes]; [self.devices removeallobjects]; nserror *error = nil; apirequest *apirequest = [[apirequest alloc]init]; [apirequest showcompleteddata]; nsmanagedobjectcontext *managedobjectcontext = [self managedobjectcontext]; nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"completedshipmentdetails"]; self.devices = [[managedobjectcontext executefetchrequest:fetchrequest error:nil] mutablecopy]; nsentitydescription *entity = [nsentitydescription entityforname:@"completedshipmentdetails" inmanagedobjectcontext:managedobjectcontext]; [fetchrequest setentity:entity]; nsarray *fetchedobjects = [managedobjectcontext executefetchrequest:fetchrequest error:&error]; } }
now if press segmented control button index 1 im getting following error
- terminating app due uncaught exception 'nsrangeexception', reason: '* -[__nsarraym objectatindex:]: index 2 beyond bounds [0 .. 1]' * first throw call stack: (0x2867d5f7 0x36347c77 0x28591157 0x15bbd3 0x2bde795d 0x2bde7a1f 0x2bddd141 0x2bbf51cb 0x2bb1f19f 0x2b54af65 0x2b546951 0x2b5467d9 0x2b5461c7 0x2b545fd1 0x2b5989f1 0x2fe5f82f 0x295a71ed 0x286333a5 0x286437f3 0x2864378f 0x28641db1 0x2858eb31 0x2858e943 0x2f952051 0x2bb80f21 0x164195 0x368e3aaf) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb)
how can sort out?
Comments
Post a Comment