views:

34

answers:

2

Hello

I have a problem in my code. I have an application TabBar controller, with 2 tabs. The first tab is a map, and the second a list of cities(table view). When I click in a city, the application center the map in the city that I selected. So far so good. My problem is that I have a refresh button on the mapview, and I want that, when I click on it can refresh the last city that I selected. I thought I could do it by getting the value of indexpath.row in my list of cities. But I do not know how, and if it's a good idea.

Any suggestions? Thanks

A: 

You would have been showing cities with the help of an array, if that is the case you should make a class level NSInteger and save your indexpath.row in that.

Madhup
A: 

Of course you could store the row value into some member variable, like indexOfLastCitySelected, for later access. But I wouldn't do it this way, maybe later you'll add some filter mechanisms which may change the amount of cities visible in the tableview so that the same city will have another row index.

I suppose you have some datasource that you populate your list from - I'd either check which item from the datasource is the last selected city and then keep a reference or an index value (only use index if the datasource itself is static).

Toastor
yes i have a data source with the list of cities, an id and the coordinates. but how can i do that ?
erisa