“[CALayer release]:发送到已释放实例的消息”在 UIViewController 中

发布于 2024-11-04 11:44:00 字数 1811 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ弥猫深巷。 2024-11-11 11:44:00

由于您在 viewDidLoad 方法中既没有分配也没有保留 labellabelView ,所以您不能在这里释放它们(您过度释放了它们)。

Since you have neither allocated nor retained label and labelView in your viewDidLoad method you may not release them here (you are overreleasing them).

浅听莫相离 2024-11-11 11:44:00

因为你做了一些不需要的释放,比如类方法的返回值。您可以在 -(void)dealloc 中释放所有重新训练的对象

Because you did some unwanted releases, like the class method return value. you can release all you retrain object in -(void)dealloc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文