“[CALayer release]:在UIViewController中发送给deallocated instance的消息”

时间:2011-05-02 10:08:32

标签: iphone objective-c release android-mapview calayer

我在UIViewController中有一个MapView。当我尝试在viewDidUnload之后加载视图时,它会崩溃:

- [CALayer release]:发送到解除分配的实例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”和“label”是IBOutlets。

2 个答案:

答案 0 :(得分:7)

由于您在label方法中既未分配也未保留labelViewviewDidLoad,因此您可能不会在此处发布它们(您过度发布它们)。

答案 1 :(得分:0)

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