开发者

Message Sent To Deallocated Instance Error

I am getting a crash saying *** -[CFString release]: message sent to deallocated instance 0x7021e80 in my dealloc method for line [muscleURL release];

The init for muscleURL is @property (nonatomic, retain) NSString *muscleURL;

This only happens when I click the done button in my NavBar. Here is the related code:

- (void)viewDidLoad
{
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)];
    [self.navigationItem setRightBarButtonItem:doneButton];
    [doneButton release];
}

-(void)dismissView
{
    [self开发者_JAVA百科.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -3)] animated:YES];
}

Edit:

In the parent view, parent view's muscleURL is init like this

-(void)didSelectRowAtIndexPath
{
    NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
    detailViewController.muscleURL = muscleURL;
}


    NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];

This returns an auto released object so you do not need to release it in your dealloc method as the system has already deallocated the memory. It might be a good idea for you to read up on Objective-C memory management, there is a document on the Apple Developer website.


Try this.

- (void)viewDidLoad
{
UIBarButtonItem * doneButton = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)]autorelease]; 
[self.navigationItem setRightBarButtonItem:doneButton];

}

-(void)didSelectRowAtIndexPath
{
NSString *tempURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
detailViewController.muscleURL = tempURL;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜