我在UIViewController中有一個MapView。當我嘗試它viewDidUnload後加載視圖其與此消息崩潰:「[CALayer發佈]:發送到釋放實例的消息」在UIViewController中
- [CALayer的發行]:消息發送到釋放實例0x29aea0
,我認爲我做的一切必要的事情,我應該做我的viewDidUnload:
- (void)viewDidUnload {
[super viewDidUnload];
locationManager.delegate = nil;
[locationManager release];
locationManager = nil;
mapView.delegate = nil;
[mapView release];
mapView = nil;
}
我的MapView是在一個配置在xib文件中的UIView中。我的VC永遠不會被釋放。
我一直在搜索一下,但我找不到答案。
編輯
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
[label setFont:[UIFont fontWithName:@"Sansation" size:28]];
[label setShadowOffset:CGSizeMake(0, 1)];
[label setShadowColor:[UIColor grayColor]];
self.navigationItem.titleView = labelView;
[label release];
[labelView release];
UIBarButtonItem *checkInButton = [[UIBarButtonItem alloc] initWithTitle:@"Checka In" style:UIBarButtonItemStylePlain target:self action:@selector(checkIn)];
[[self navigationItem] setRightBarButtonItem:checkInButton];
[checkInButton release];
UIBarButtonItem *clueListButton = [[UIBarButtonItem alloc] initWithTitle:@"Ledtrådar" style:UIBarButtonItemStylePlain target:self action:@selector(cluesDown)];
[[self navigationItem] setLeftBarButtonItem:clueListButton];
[clueListButton release];
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor colorWithRed:0.06 green:0.58 blue:0.88 alpha:1]];
}
「LABELVIEW」 和 「標籤」 是IBOutlets。
locationManager和mapView實際上是否真的保留了嗎?我想他們只是添加爲子視圖而沒有保留,然後'[super viewDidUnload];'可能會釋放它們,釋放會導致崩潰。 – DarkDust 2011-05-02 10:13:11
locationManager = [[CLLocationManager alloc] init];和@property(nonatomic,retain)IBOutlet MKMapView * mapView ;.這是正確的方式嗎?如果[super viewDidUnload]釋放對象,我應該在viewDidUnload中獲得exc_bad_access?該錯誤出現在viewDidAppear之後,但是在你實際看到mapView(就是網格)之前。 – 2011-05-02 10:20:52
訪問釋放對象時,您不一定會遇到訪問異常錯誤。如果新對象現在駐留在該內存位置,您也可以將*消息發送到釋放實例*錯誤或*無法識別的選擇器*。但是你現在說這個消息來自* viewDidAppear *之後,所以你應該向我們展示這個方法。 viewDidUnload方法在視圖控制器釋放其視圖(清除)時調用。 – DarkDust 2011-05-02 10:51:41