我创建了一个运行6.1版的iPhone应用程序。 在我的一个视图中,我使用的是mapview,包括注释引脚,缩放到位置。
如果首先打开所有其他视图并且mapview没有崩溃,则应用程序运行正常。 但是,如果我打开应用程序并直接进入mapview viewcontroller应用程序崩溃??
此外,该应用程序仅在我的iPhone 4S设备上崩溃,而不是在控制器???
中崩溃任何人都可以帮助我吗?
最好的问候。
这是我的mapview代码:
@interface VisPaaKortViewController ()
@end
@implementation VisPaaKortViewController
@synthesize mapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
mapView.showsUserLocation = YES;
// Do any additional setup after loading the view.
// Create a view of the standard size at the top of the screen.
// Available AdSize constants are explained in GADAdSize.h.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier". This is your AdMob Publisher ID.
bannerView_.adUnitID = @"my_publisher_id";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
//Placement of banner
[bannerView_ setFrame:CGRectMake(0,
362,
bannerView_.bounds.size.width,
bannerView_.bounds.size.height)];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
-(void) viewWillAppear:(BOOL)animated {
[self performSelector:@selector(zoomInToMyLocation)
withObject:nil
afterDelay:0];
}
- (void)zoomInToMyLocation
{
CLLocationCoordinate2D location;
location.latitude = (double) 59.778747;
location.longitude = (double) 9.292349;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:NO];
// Add an annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = location;
point.title = @"Text";
point.subtitle = @"Text";
[self.mapView addAnnotation:point];
[self.mapView selectAnnotation:[[self.mapView annotations] objectAtIndex:0] animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
答案 0 :(得分:0)
由于你没有提供太多细节,我必须猜测。我假设您使用ARC,我会尝试将self.mapView.delegate = nil;
添加到您的dealloc方法。
- (void)dealloc {
self.mapView.delegate = nil;
}
MKMapView
委托被声明为assign
而不是weak
,这意味着当viewController已经被释放时,仍然可以引用委托。
如果你不使用ARC,你仍然应该在你的dealloc中使用mapView.delegate。