“[CALayer release]:发送到已释放实例的消息”在 UIViewController 中
我在 UIViewController 中有一个 MapView。当我尝试在 viewDidUnload 之后加载视图时,它崩溃并显示以下消息:
-[CALayer release]: message sent to deallocated instance 0x29aea0
做了所有我应该做的必要的事情
- (void)viewDidUnload {
[super viewDidUnload];
locationManager.delegate = nil;
[locationManager release];
locationManager = nil;
mapView.delegate = nil;
[mapView release];
mapView = nil;
}
我想我在 viewDidUnload: My MapView is in an UIView 中 在 xib 文件中配置。我的 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”和“label”是IBOutlet。
I have a MapView in an UIViewController. When I try to load the view after its viewDidUnload it crashes with this message:
-[CALayer release]: message sent to deallocated instance 0x29aea0
I think I do all the necessary things that I should do i the viewDidUnload:
- (void)viewDidUnload {
[super viewDidUnload];
locationManager.delegate = nil;
[locationManager release];
locationManager = nil;
mapView.delegate = nil;
[mapView release];
mapView = nil;
}
My MapView is in an UIView configured in a xib-file. My VC is never deallocated.
I have been googling around for a while now but I can't find the answer.
Edit
- (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" and "label" are IBOutlets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您在
viewDidLoad
方法中既没有分配也没有保留label
和labelView
,所以您不能在这里释放它们(您过度释放了它们)。Since you have neither allocated nor retained
label
andlabelView
in yourviewDidLoad
method you may not release them here (you are overreleasing them).因为你做了一些不需要的释放,比如类方法的返回值。您可以在 -(void)dealloc 中释放所有重新训练的对象
Because you did some unwanted releases, like the class method return value. you can release all you retrain object in -(void)dealloc