为什么alloc不能在applicationWillEnterForeground中工作?

时间:2015-07-30 15:21:23

标签: ios objective-c iphone cocoa-touch

我把它放在applicationDidFinishLaunchingWithOptionsapplicationWillEnterForeground中的AppDelegate.m中:

[MAMapServices sharedServices].apiKey = kMapKey;
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;

在地图的委托方法中,我这样做:

-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
  if (self.mapView) {
     self.mapView = nil;
  }
}

applicationDidFinishLaunchingWithOptions中可行,但在applicationWillEnterForeground中_mapView的alloc无效。在nilalloc之后,它仍然是init。为什么? (顺便说一句,_mapView属性为strong,而不是weak。)

1 个答案:

答案 0 :(得分:0)

您正在使用实例变量_mapView来分配分配。 尝试使用

self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

该财产是否很弱?