views:

118

answers:

2

For some reason I cannot access the view as a property

MyAppDelegate *APPDELEGATE=((MexicanWaveAppDelegate*)[[UIApplication sharedApplication] delegate]);
[APPDELEGATE.viewController view];
APPDELEGATE.viewController.view; //Accessing unknown 'view' component of a property

I have been able to access view as a property for other view controllers and it is a property in the doc. Can you explain this behavior?

+1  A: 

Either APPDELEGATE.viewController is not of type UIViewController (or a derived class), or you didn't include the header for MexicanWaveAppDelegate (MexicanWaveAppDelegate.h)

Philippe Leybaert
It actually wasn't either of these, but your answer was very helpful
Casebash
A: 

The problem was actually caused because my app delegate .h file (MexicanWaveAppDelegate.h) didn't contain information about what type the view controller (MexicanWaveViewController) was. This means that any class importing MexicanWaveAppDelegate.h would have its MexicanWaveViewController property as an 'opaque type' (a type about which no information is known).

This problem can be solved by changing MexicanWaveAppDelegate.h in either of the following ways:

  • Importing the "MexicanWaveViewController.h"
  • Providing a forward declaration for MexicanWaveViewController
Casebash