ios - Why does this loop cause a crash if nothing is found in the array -


i'm totally lost , not sure how phrase question. have loop can see below. if if statement within loop proves true indexpath assigned value, loop completes (there 49 objects in _samplepictures array)and enters if (found) , loads found data. if the condition not true , nothing found instead of entering if(!found) app crashes. have tried various structures of current coding scheme. removed loop , entered if(!found) supposed to. (ooooodddddddd)

this statement in viewdidload , directly above (the if statement not viewdidload) if statement determines contents of _samplepictures.

it may useful know images in array define this:

#define img_71          [uiimage imagenamed:@"imagename.jpg"] 

the array structured in way:

_samplepictures = @[@{@"image": img_71, @"title" : @"title of item", @"description" : @"complete description of item"}];  if (fromkitinstructions) {     int = 0;      nsindexpath *indexpath;     found = false;      while(i <= _samplepictures.count)     {         if([_samplepictures[i] objectforkey:@"title"] == instructionname)         {             indexpath  = [nsindexpath indexpathforrow:i insection:0];             = 50;             found = true;         }         else         {             i++;         }     }      if(found)     {         [self tableview:self.tableview didselectrowatindexpath:indexpath];     }      if(!found)     {         uialertview *alert = [[uialertview alloc] initwithtitle:instructionname message:@"we sorry kit id searched not found. press button return instructions viewing." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:@"say hello",nil];         [alert show];     } } 

here button gets code:

-(void)goto:(id)sender {     viewcontroller *gogallery = [[viewcontroller alloc] initwithnibname:@"viewcontroller" bundle:[nsbundle mainbundle]];     gogallery.setflag = no;     gogallery.fromkitinstructions = yes;     gogallery.instructionname = instructionname;     [self.navigationcontroller pushviewcontroller:gogallery animated:yes];  } 

debugger shows this:

2014-05-30 15:08:37.873 techbook[3932:60b] [info] <homeviewcontroller: 0xc67bb00> loaded 2014-05-30 15:14:24.268 techbook[3932:3c03] void senddelegatemessage(nsinvocation *): delegate (webview:decidepolicyformimetype:request:frame:decisionlistener:) failed return after waiting 10 seconds. main run loop mode: kcfrunloopdefaultmode 2014-05-30 15:14:43.204 techbook[3932:60b] *** terminating app due uncaught exception 'nsrangeexception', reason: '*** -[__nsarrayi objectatindex:]: index 49 beyond bounds [0 .. 48]' *** first throw call stack: (     0   corefoundation                      0x01f3d1e4 __exceptionpreprocess + 180     1   libobjc.a.dylib                     0x01cbc8e5 objc_exception_throw + 44     2   corefoundation                      0x01ef18b2 -[__nsarrayi objectatindex:] + 210     3   corefoundation                      0x01fbbf48 -[nsarray objectatindexedsubscript:] + 40     4   techbook                            0x0000ae3d -[viewcontroller viewdidload] + 22381     5   uikit                               0x0088e33d -[uiviewcontroller loadviewifrequired] + 696     6   uikit                               0x0088e5d9 -[uiviewcontroller view] + 35     7   uikit                               0x008a8942 -[uinavigationcontroller _startcustomtransition:] + 778     8   uikit                               0x008b58f7 -[uinavigationcontroller _startdeferredtransitionifneeded:] + 688     9   uikit                               0x008b64e9 -[uinavigationcontroller __viewwilllayoutsubviews] + 57     10  uikit                               0x009f70d1 -[uilayoutcontainerview layoutsubviews] + 213     11  uikit                               0x007de964 -[uiview(calayerdelegate) layoutsublayersoflayer:] + 355     12  libobjc.a.dylib                     0x01cce82b -[nsobject performselector:withobject:] + 70     13  quartzcore                          0x001f145a -[calayer layoutsublayers] + 148     14  quartzcore                          0x001e5244 _zn2ca5layer16layout_if_neededepns_11transactione + 380     15  quartzcore                          0x001e50b0 _zn2ca5layer28layout_and_display_if_neededepns_11transactione + 26     16  quartzcore                          0x0014b7fa _zn2ca7context18commit_transactionepns_11transactione + 294     17  quartzcore                          0x0014cb85 _zn2ca11transaction6commitev + 393     18  quartzcore                          0x0020a5b0 +[catransaction flush] + 52     19  uikit                               0x0076d9bb _uiapplicationhandleeventqueue + 13095     20  corefoundation                      0x01ec677f __cfrunloop_is_calling_out_to_a_source0_perform_function__ + 15     21  corefoundation                      0x01ec610b __cfrunloopdosources0 + 235     22  corefoundation                      0x01ee31ae __cfrunlooprun + 910     23  corefoundation                      0x01ee29d3 cfrunlooprunspecific + 467     24  corefoundation                      0x01ee27eb cfrunloopruninmode + 123     25  graphicsservices                    0x036d75ee gseventrunmodal + 192     26  graphicsservices                    0x036d742b gseventrun + 104     27  uikit                               0x0076ff9b uiapplicationmain + 1225     28  techbook                            0x00003b1d main + 141     29  libdyld.dylib                       0x027ee701 start + 1     30  ???                                 0x00000001 0x0 + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception 

while(i <= _samplepictures.count) 

change to:

while(i < _samplepictures.count) 

the array runs 0-48, _sampepictures.count returns 49 total objects. when hit last run through array, count total greater final index.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -