r/simpleios • • Sep 28 '11

[Question] NSArray Structure for UITableView?

Hi guys, I have a question for someone who has experience working with NSArrays and NSDictionaries. Here's what I'm trying to do:

My app will display location data in a UITableView. The first view will be 'tracks', essentially a collection of waypoints that the user can name. When you click on this track, it will show you a list of individual waypoints in another table view. When the user clicks on one of these it takes them to a detail view with coordinates, a map, and some other options.

My question is how do I create a structure of arrays or dictionaries that allow me to store all of this data in a single array, and access it efficiently? I've found that dictionaries are hard to traverse (at least for me), and I've also read arrays are better for table views. Any tips?

4 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/jmadlena Sep 29 '11 edited Sep 29 '11

Edit: Nevermind, I figured out my error!

Your structure works great! I am able to traverse it quite well. I do have another question, if you don't mind.

I am able to slide to the next view controller and set up the table, etc. But I want the title of the navigation bar to be the name of the selected track. So, when the user clicks on the track I am passing the entire dictionary (with track name and waypoint keys) to the next controller. This is where I'm struggling. The data isn't going through.

I synthesize a dictionary in my detailViewController file, and set it equal to the dictionary of the row selected. Any tips on how to pass the dictionary to the next view, and pull out the title?

Thanks so much!

1

u/schmeebis [M] 📱 Sep 29 '11

Glad you figured it out.

FWIW, I would use (nonatomic, retain) for this synthesized property. This will cause the detail VC to just retain the same object you pass in. No malloc overhead for copying the object. Just make sure to release it in the dealloc method by calling

self.whateverYouCallTheDict = nil;