This might be a simple question, but I moved one of my apps from a view based application to a window-based application. In the original app, I had one view with a view controller and a map. I had a class that parsed some data and sent it to the view controller. I used the following code from ClassA to send data to ClassB which added an annotation.
AnnotationProblemAppDelegate *appDelegate = (AnnotationProblemAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.viewController loadOutAnnotations];
I cannot alloc the view controller because it will create a new instance of the view controller. I need to pass a reference to the view controller when creating ClassA.
Now that the map view is nested within a UITabBArController, I am not sure exactly how I pass the reference from ClassA to the ClassB with the map. Do I need to add a new delegate method or initiate a protocol? I hope this is enough information. Let me know if I can clarify any further.
Thank you in advance!
I figured it out myself. To call [[UIApplication sharedApplication] delegate], I had to some coded to connect everything up in my window-based application. I completed the following steps to hook everything up:
I referenced the class in MyAppDelegate.h before @interface
@class MyClass
Declare an IBOutlet for my class
IBOutlet MyClass *myClass;
Make my IBOutlet a property
@property (nonatomic, retain) IBOutlet MyClass *myClass;
Synthesize the property (make sure to also release it)
@synthesize myClass;
Connect the IBOutlet to the view controller in Interface Builder. In my app which had a Tab Bar Controller and a Navigation Controller inside the Tab Bar Controller, I had to make sure the IBOutlet went to the view controller which was nested with in the navigation controllers.
Finally, to reference myClass in any of my other classes, I called UIApplication sharedApplication with the following code:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.myClass methodBeingCalled];
I hope this helps if you come across the same problem!