Reputation: 29
I came across this post here (link below) and it states that you can replace:
[window addSubview: someController.view];
with:
self.window.rootViewController = self.someController;
My Base SDK for All Configurations is set to Latest iOS (currently set to iOS 4.2), however when I try to build the project I get this error: Request for member, 'mainMapView' in something not a structure or union.
Adding it with the commented out addSubview: works fine though. This is the code in question...
#import "MakeView2AppDelegate.h"
#import "MainMap.h"
@implementation MakeView2AppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MainMap *mainMapView = [[MainMap alloc] initWithNibName:nil bundle:nil];
//[self.window addSubview:mainMapView.view];
self.window.rootViewController = self.mainMapView;
[self.window makeKeyAndVisible];
return YES;
}
self.window.rootViewController vs window addSubview
Upvotes: 1
Views: 3829
Reputation: 13180
you have not create property for mainMapView.
so you can not write self.mainMapView
you have to use mainMapView.
for more help see this :
Understanding your (Objective-C) self
http://useyourloaf.com/blog/2011/2/8/understanding-your-objective-c-self.html
Upvotes: 0
Reputation: 7895
In your example, you are calling self.mainMapView, but unless mainMapView is a property on the class, this won't work. If you remove the "self." from it, it will work fine.
Upvotes: 1
Reputation: 26752
Since iOS4 this has been the default behaviour in the templates in Xcode4. It's probably better to use addSubview for backwards compatibility as the other method does not work with iPhone OS 3.x
Upvotes: 1
Reputation: 8323
This is because you're looking for mainMapView
as a property
of the app delegate. Change that line to:
self.window.rootViewController = mainMapView;
This is assuming that the MapView
class inherits from UIViewController
, however. Does it?
Upvotes: 3