I have the following code in viewDidLoad (to set a title in the nav bar) that’s crashing with a “message sent to deallocated instance” error:
UILabel * label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,45,45)] autorelease];
label.textColor = [UIColor whiteColor];
label.backgroundColor=[UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20];
label.font = [UIFont fontWithName:@"Mayfield Regular" size:15];
self.navigationItem.titleView = label;
label.text=@"SEARCH"; //CUSTOM TITLE
[label sizeToFit];
[label release];
How can I go about correcting this?
Thanks for any help
You are overreleasing the label. You call
autoreleasein the first line you posted and then you also callreleasein the last line you posted. Only do one of these.