Iphone 为什么无法在iOS中将mapView.showsUserLocation设置为“是”?

Iphone 为什么无法在iOS中将mapView.showsUserLocation设置为“是”?,iphone,ios5,mkmapview,Iphone,Ios5,Mkmapview,我在这里发现了一个类似的老帖子: 我有以下代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; locationMana

我在这里发现了一个类似的老帖子:

我有以下代码:

- (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?为什么我不能设置为是

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

是否可以发布日志NSLog@map:%@,%d,地图视图,[地图视图显示位置]?您在哪里分配了mapview..?您是在设备上还是在模拟器上进行测试?我想您忘记分配mapview了。