2012-04-21 180 views
0

我在這裏發現了類似的舊帖子: showsUserLocation does not display blue dot in iPhone 4.0爲什麼我不能在iOS中將mapView.showsUserLocation設置爲YES?

我有這樣的代碼:

- (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

+0

你可以發佈'NSLog日誌(@「map:%@,%d」,mapView,[mapView showsUserLocation]);'? – Francesco 2012-04-21 15:48:04

+1

你在哪裏分配了mapview ..? – 2012-04-21 15:52:47

+0

您是在設備上還是在模擬器上測試? – jmstone617 2012-04-21 16:27:36

回答

0

您的應用程序可能已經完成啓動,但可能您的視圖尚未加載。如果視圖沒有加載其中的mapView,它將不會有。嘗試將showsUserLocation代碼移動到viewDidLoad

相關問題