iPhone UIPickerView and array - iphone

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 :)

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.

Related

store selected rows on PFQueryTableViewController

I have a tableview that is of type PFQueryTableViewController and gets its value from Parse cloud. The tableview works fine but now I need to allow the user to:
Select a row
Record in a column (string array) on Parse-Users table what rows have been selected (need to record on parse that - i will use these values for other things later)
When the user comes back and opens the tableview he can see what rows have been selected last time he was in the app
I am not sure if PFQueryTableViewController has any methods ready for that. Could anyone give me some guidance?
I would prefer to use parse cause there are so much stuff out of the box. But if not, that is fine as well.
Also, code samples from similar solutions would be great. Just need to know the best approach.
The table view controller is there for display, it will tell you about selection, but it won't automatically maintain a record of selected items in the back end. You need to decide on the appropriate way to store the selections (array of pointers is better than an array of strings) and update the store and table display appropriately. There is no standard approach to this.

How to give relation among group of NSMutableArray?

my application is world guide. there is a 4 tableview and 4 mapview.
Continent
Country
City
Place
I have taken NSMutableArray for each above item and allocate them in view did load . when Asia is selected from the Continent table then only Asian countries should display from the country array. if country is selected then only city of respective country should be display in city table view from the city array like vice for place. it's like a tree. it is too lengthy to work with an array. Please guide me if another way is exist that make this task easy.
I think the better way to implement should be:
Use NSMutableArray only to store the top level Object.
Use NSMutableDictionary to store the mid & lower level objects.
Store the NSMutableDictionary in your NSMutableArray at each index of your top level Object.
Put the key as the Continent name in top NSMutableDictionary & value as country name & follow the same for next level.
In this case, you have to maintain only a single NSMutableArray to work. No need to handle 4-5 different arrays.
Hope it works for you.
To handle the data or categorize the data with the way you have the data about all four objects is quite complex because there is no key value pair by which you can identify that which country comes under which continent and which city comes under which country and so on.
So what you have to do is, use web service by which you can fetch the categorized data.
Here is link of web service by which you can simply hit the URL and catch the XML as the response.
URL : http://ws.geonames.org/countryInfo?
Above URL gives you the XML as the response. Like this :
<geonames>
<country>
<countryCode>AD</countryCode>
<countryName>Andorra</countryName>
<isoNumeric>020</isoNumeric>
<isoAlpha3>AND</isoAlpha3>
<fipsCode>AN</fipsCode>
<continent>EU</continent>
<continentName>Europe</continentName>
<capital>Andorra la Vella</capital>
<areaInSqKm>468.0</areaInSqKm>
<population>84000</population>
<currencyCode>EUR</currencyCode>
<languages>ca</languages>
<geonameId>3041565</geonameId>
<west>1.4071867141112762</west>
<north>42.65604389629997</north>
<east>1.7865427778319827</east>
<south>42.42849259876837</south>
</country>
.
.
.
and so on...
or if you want JSON format. take the following URL :
URL api.geonames.org/countryInfoJSON?username=demo&formatted=true
So now you are just few steps away from your solution.
Now Do the XML parsing and filter the data according to your requirement.
or if you want to have the detail knowledge about this web service
just visit : http://geonames.r-forge.r-project.org/
Hope it works for you.
I suppose you have all the data about Continent, Country, City and Place. In this situation the way of connecting all 4 arrays is totally depends upon the format of data you have for displaying on TableViews.
Whether it is a array of string or array of dictionary for each item or JSON or XML.
Please tell me the data format. After that i'll try my best.

Saving to CoreData - Add to Top

All,
Is it possible to save to the top of the CoreData? If so, how?
For example, every time something is added to the data store, I want it to be inserted at the top. This way, when the results are fetched they would come back sorted by most recent first without having to save the NSDate and fetch with a predicate. Here is a crude example:
Most recent
Earlier
Yesterday
Last Week
Thanks,
James
What is the "top"?
Core Data does not assign any particular order to the objects it stores. If you want to impose some order on the objects, add an attribute to the entity that you want to be ordered and then sort on that attribute when you fetch the objects. So, you could add a serialNumber attribute that always increases. Sorting on that serial number would order the objects.
Add a creationDate in the model, and the following code to your custom implementation of the object:
- (void)awakeFromInsert {
[self setPrimitiveCreationDate:[NSDate date]];
}

iphone version of Android contacts attributes?

I'm looking for a way to query contacts in my iPhone app based on a few things. First I only want contacts that have a phonenumber. Second, id like to sort the contacts in order of the number of times contacted.
Android provides attributes that makes this possible and easy to do.
I can't really say that I know the answer, but I believe I know where to find the answer:
http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html#//apple_ref/doc/uid/TP40007744-CH1-SW1
Here are some quotes from that document that seems relevant:
There are two ways to find a person record in the Address Book database: by name, using the function ABAddressBookCopyPeopleWithName, and by record identifier, using the function ABAddressBookGetPersonWithRecordID. To accomplish other kinds of searches, use the function ABAddressBookCopyArrayOfAllPeople and then filter the results using the NSArray method filteredArrayUsingPredicate:.
To sort an array of people, use the function CFArraySortValues with the function ABPersonComparePeopleByName as the comparator and a context of the type ABPersonSortOrdering. The user’s desired sort order, as returned by ABPersonGetSortOrdering, is generally the preferred context.
Those quotes were both found on this page. I hope it helps.

Tableview with sections managed by fetched results controller

I'm quite new to CoreData and need help with one issue. I have tableview which simply lists cities stored in SQLite db. City is defined by "cityId" and "name" attributes.
Data are fetched using NSFetchedResultsController and everything works fine except that I can't figure out how to make FetchedResultsController to group cities by first letter of city names.
When I supply "name" for sectionNameKeyPath argument of initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName: method, it creates section for each city, which is obviously something I don't want. I can't figure out how to create an expression which would make it work in way I need.
thanks for any tips and/or advices on this
Matthes