Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve an index from an array, use this index to select a row in pickerview
    text
    copied!<p>I have an array (catArray), coming from a core data fetch. I'm using this array to populate my pickerview (categoryPicker). Also, I have a note loaded when the view appears, and this note (coming from core data too) has a "category" attribute, which matches with one of the categories of catArray. </p> <p>What I would like to do is, when the view appeared, grab the category attribute of the note, search the string result in my catArray, get the index, and select the right row for the pickerview. Here is my code :</p> <pre><code>- (void)viewDidLoad { Notes *editNote = (Notes *)[noteArray objectAtIndex:0]; NSString *tmpString = [editNote category]; NSLog(@"tmpstring : %@", tmpString); NSLog(@"cat array : %@", catArray); NSInteger indexOfTheObject = [catArray indexOfObject:tmpString]; [categoryPicker selectRow:indexOfTheObject inComponent:0 animated:YES]; } </code></pre> <p>Here are the logs results : </p> <pre> 2013-11-07 14:09:25.393 Simple Notes 1[14351:a0b] tmpstring : category two 2013-11-07 14:09:25.395 Simple Notes 1[14351:a0b] cat array : ( " (entity: Categories; id: 0x89f1770 ; data: )", " (entity: Categories; id: 0x89d9230 ; data: )", " (entity: Categories; id: 0x8968420 ; data: )", " (entity: Categories; id: 0x8968430 ; data: )", " (entity: Categories; id: 0x89cdc10 ; data: )" ) 2013-11-07 14:09:25.404 Simple Notes 1[14351:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableIndexSet addIndexesInRange:]: Range {2147483647, 1} exceeds maximum index value of NSNotFound - 1' </pre> <p>So I know the string I'm looking for is okay, my array is not empty neither, but I cannot figure out why I cannot find the right index ? Any suggestion ? Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload