Hi have an newbie issue with objective-c, cocoa & iPhone. I’ve declared mapView in my application delegates applicationDidFinishLaunching:application: which is instance/pointer of MKMapView class. mapView is a member of my application delegate.
In my view controller in viewDidLoad: I get instance of my application delegate with the following:
appDelegate = [[UIApplication sharedApplication] delegate];
My view controller also has got MKMapView *mapView as a member. In viewDidLoad: I try to set it this way:
mapView = [appDelegate mapView];
but it seems that I’m not able to get pointer or “reference” to the actual mapView because when I try to [mapView setRegion:region animated:YES]; it does not work. How ever [[appDelegate mapView] setRegion:region animated:YES]; does work.
So the question is how do I get a pointer to appDelegates mapView from my view controller?
It sounds like you’re caching your app delegate’s mapView member. However, it’s possible that at the time you perform this cache, it’s not yet instantiated (setting a breakpoint at this location will reveal that to you).
The answer to your question is: [appDelegate mapView] returns a pointer to the appView member. However, if that member is nil, that’s what you’ll get back.