我在行*** -[CFString release]: message sent to deallocated instance 0x7021e80
的dealloc方法中遇到[muscleURL release];
的崩溃事件
muscleURL
的初始值为@property (nonatomic, retain) NSString *muscleURL;
仅当我单击导航栏中的完成按钮时才会发生这种情况。以下是相关代码:
- (void)viewDidLoad
{
UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)];
[self.navigationItem setRightBarButtonItem:doneButton];
[doneButton release];
}
-(void)dismissView
{
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -3)] animated:YES];
}
编辑:
在父视图中,父视图的muscleURL
就像这样
-(void)didSelectRowAtIndexPath
{
NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
detailViewController.muscleURL = muscleURL;
}
答案 0 :(得分:0)
试试这个。
- (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;
}
答案 1 :(得分:0)
NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
这将返回一个自动释放的对象,因此您不需要在dealloc方法中释放它,因为系统已经释放了内存。阅读Objective-C内存管理可能是一个好主意,Apple开发人员网站上有一个文档。