Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jackal123uk

macrumors member
Original poster
Jan 13, 2007
69
3
England
Hi all,

Over the past couple of months I've put together my first iOS app and on the whole it's going well. I'll be the first to admit that biggest my downfall is not fully understanding the underlying objective C foundation, and I find Apple's documentation on the subject quite hard going.

My app in similar to the Contacts app; it reads a SQL database to generate a tableview, where each row drills down to an "details" page which displays data and a map thumbnail taken from the database. The map thumbnail is a small mapview generated with hardcoded location co-ordinates from the database. When the user taps the thumbnail a larger map with interaction enabled is displayed.

The problem is that no matter how I try I cannot pass the co-ordinate data used to generated the thumbnail on to the main mapview. I've tried to reference the co-ordinates of the detailview class from within the mapview class and tried defining the new co-ordinates of the mapview class from within the detailview class. Methods which have worked before...

Anyone know of any good tutorials on how to share variables between views/classes? Any help would be greatly appreciated.

Thanks in advance.
 
When you push the new view (with your big map), you just use the initWithNibName?
you could try creating your own init method, where you pass an object, which holds all the data, then you can retain the data in your new controller, and use it there :) or save one in a singleton method, but this is not what you're looking for in this case i think.
 
When you push the new view (with your big map), you just use the initWithNibName?
you could try creating your own init method, where you pass an object, which holds all the data, then you can retain the data in your new controller, and use it there :) or save one in a singleton method, but this is not what you're looking for in this case i think.

Exactly what he said. Create an initWithYourObject:YourObj method, and just call it: [[YourViewController alloc] initWithYourObject:Object];
 
Another way is to create properties for your coordinates in your map view's controller and then set those properties after your instantiate it but before you present it (whether modally or pushed on the nav stack or whatever). Then in the viewDidLoad: you can do what you need to based on the values of those properties. This is a pretty common approach that Apple uses in various places in their sample apps and even in their UITableViewController delegate method for didSelectRowAtIndexPath:.

Anyways, the overall issue you are dealing with is called data persistence and there are a variety of solutions you can use to achieve it. Search this forum for "sharing values" and/or "data persistence" and you will find a number of other threads already discussing the various solutions.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.