Reputation: 23
I'm looking for best way to populate UIPickerView with data from webservice. I have web service:
Country1Country1CODE
Country2Country2CODE
Country3Country3CODE
I made all parsing correct and i can reach all values of service like service.country or service.code.
Problem is what in UIPickerView I need to show list countries, but return as value selected country code. (i hope i explained understandable). All day i was looking for best way how to do it, but I didn't found nothing... Thanks for you help and wasted time :)
Upvotes: 1
Views: 263
Reputation: 54415
Once you've retrieved the data from the web server, your best bet is to use an NSDictionary as a repository for the data, which you'd use to store the country codes as objects with the country name as the key.
i.e.: ... dictionaryWithObject:@"826" forKey:@"United Kingdom"
You could then use the NSDictionary allKeys method to obtain an NSArray of country names to populate the UIPickerView with and (once the user has selected a country) can trivially retrieve the corresponding country code via the NSDictionary objectForKey method.
Upvotes: 1