Note that there are some explanatory texts on larger screens.

plurals
  1. PONSDictionary from P-list with UIPickerView
    text
    copied!<p>I'm having a problem with my picker in one of my apps. I have an NSDictionary obtained from a property list that contains a bunch of keys, which in turn contain a bunch of strings. I have two components, each one should have the same list of strings within. I also have a slider that I want to use to allow the user to change keys. So when the slider's value goes from 0 to 1 the key at index 1 in the dictionary should load its contents into the pickerview's components.</p> <p>It's working as far as loading the new contents into the picker based on the slider. I've been using the slider's tag as the variable to dictate which contents get loaded. The problem is that after loading a new list of items the program crashes, I'm thinking that the number of rows needed isn't getting update or something but I'm just not experienced enough with UIPickerView to isolate the problem myself without spending more hours than I've already used trying to figure this out myself.</p> <p>Here are my delegate/data methods for the picker:</p> <pre><code>#pragma mark - #pragma mark Picker Delegate/Data Methods -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { //aryNames is an NSArray instance variable that contains the values for the components of the picker if (component == 0) return [self.aryNames count]; return [self.aryNames count]; } -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //I think this is where my problem is //I'm using a string to select the object // at the index of the slider's location to // fill up the instance variable with new data. //Anyway, it works fine if I have two different arrays hardcoded //but I'd really like to have this load dynamically because //there are a lot of keys and this way I could add and remove keys without //worrying about changing code NSString *selectedType = [self.aryKeys objectAtIndex:slideUnitTypes.tag]; NSArray *newNames = [dictAllNames objectForKey:selectedType]; self.aryNames = newNames; return [aryNames objectAtIndex:row]; } //I'm pretty sure that the method below is not the problem -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component { if (component == 0) { [firstValueHeading setText:[aryNames objectAtIndex:row]]; } else { [secondValueHeading setText:[aryNames objectAtIndex:row]]; } } </code></pre> <p>If it wasn't descriptive enough or you need to see more of my code please tell me. This problem has been a real bugger in an otherwise smooth project. Thanks.</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