0

我在这里找到了一个类似的旧帖子: 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

4

1 回答 1

0

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

于 2012-04-22T05:57:40.850 回答