为什么我不能在iOS中将mapView.showsUserLocation设置为YES?

时间:2012-04-21 15:17:22

标签: iphone ios5 mkmapview

我在这里发现了一个类似的老帖子: showsUserLocation does not display blue dot in iPhone 4.0

我有这段代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    locationManager=[[CLLocationManager alloc]init];

    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    //[locationManager startUpdatingLocation];
    mapView.showsUserLocation=YES;    
    NSLog(@"bool: %d", [mapView showsUserLocation]);

    // Override point for customization after application launch.
    self.viewController = [[[WhereamiViewController alloc] initWithNibName:@"WhereamiViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

为什么NSLog(@"bool: %d", [mapView showsUserLocation])显示0,而不显示1?为什么我不能将它设置为YES

1 个答案:

答案 0 :(得分:0)

您的应用程序可能已完成启动但可能您的视图尚未加载。如果视图未加载,则其中的mapView也不会加载。尝试将showsUserLocation代码移动到viewDidLoad