NSArray view in UITableView

advertisements

I have a UITableView that should display some data (Countries for example), clicking one of them should load new UITableView which will display another data relevant to the cell I had clicked on (for example cities in the country), clicking the city should display me information about it. So, this everything will of course use UINavigationController, but how must I arrange the data for Countries->Cities?


I think the most proper way to do it is to develop custom classes for your model. Think of it this way: is a country really just a string? In some apps it may be, but in your's it's at least an object that has a name and contains cities.

Is a city just a string? Again, in some representation, maybe it is, or maybe it associates more data, like population or the mayor's name, or whatever. Is the mayor just a name? ... and so on.

Once you realize this, your table representation becomes better than an array of strings, and (with due respect to the other answer) better than a dictionary. Instead, your table is backed by an array of Country objects. When one is selected, you can hand the selected country self.countries[indexPath.row] to a new view controller with a table that asks it for it's cities: NSArray *cities = self.country.cities... and so on.