self.window.rootViewController = self.someController not working?
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 开发者_JAVA技巧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
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?
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.
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
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
精彩评论