1

应用加载时 Mapview 加载成功。

然后,在第一次更改视图并返回主视图并且 viewDidAppear 初始化后,Mapview 加载成功。

但是在第一个viewDidAppear实例之后,mapview地图没有加载,背景是黄色的。在 mapview 地图再次出现之前,我必须重新启动应用程序。

这是因为我在更改视图时没有正确释放地图视图吗?我正在使用 ARC。

编辑(katzenhut):OP 在评论中发布了此代码:Appdelegate.m

if(self.locationManager==nil){
     _locationManager=[[CLLocationManager alloc] init];
     _locationManager.delegate=self;
     self.locationManager = _locationManager;
 }

视图控制器.m

- (void)viewDidAppear:(BOOL)animated{


    [self setValuesFromPreferences];
    appDelegate.refresh = FALSE;
    theMapView.showsUserLocation = YES;
    [theMapView setCenterCoordinate:appDelegate.locationManager.location.coordinate   zoomLevel:zoom animated:YES];
    [super viewDidAppear:animated];
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
    [theMapView setCenterCoordinate: appDelegate.locationManager.location.coordinate zoomLevel:zoom animated: YES];
}

地图视图控制器.m

#import "MapViewController.h"


@implementation MapViewController
@synthesize theMapView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    appDelegate = (theAppDelegate *)[UIApplication sharedApplication].delegate;
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}
- (void)viewDidAppear:(BOOL)animated
{
    theMapView.showsUserLocation = YES;
    pendingRegionChange = YES;
    isTracking = YES;
    [theMapView setCenterCoordinate:appDelegate.locationManager.location.coordinate zoomLevel:14 animated:YES];
    [super viewDidAppear:animated];


}

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    if( isTracking )
    {
        pendingRegionChange = YES;
        [theMapView setCenterCoordinate:appDelegate.locationManager.location.coordinate zoomLevel:14 animated:YES];
    }
}

-(void) mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
    if( isTracking && ! pendingRegionChange )
    {
        isTracking = NO;
    }

    pendingRegionChange = NO;
}

@end

解决了 viewcontroller.m 中以下代码的问题:

- (void)viewDidDisappear:(BOOL)animated{
    [timer invalidate];
}
4

0 回答 0