Iphone 将视图推到导航堆栈上后释放会导致exc\u bad\u访问错误
以下代码位于tableView DidSelectRowatineXpath中。如果发布未注释,则我会收到错误:Iphone 将视图推到导航堆栈上后释放会导致exc\u bad\u访问错误,iphone,objective-c,uinavigationcontroller,pushviewcontroller,Iphone,Objective C,Uinavigationcontroller,Pushviewcontroller,以下代码位于tableView DidSelectRowatineXpath中。如果发布未注释,则我会收到错误: ComicDetailsViewController * comicDetailsViewController = [[ComicDetailsViewController alloc] initWithNibName:@"ComicDetailsViewController" bundle:nil]; comicDetailsViewController.comic
ComicDetailsViewController * comicDetailsViewController = [[ComicDetailsViewController alloc] initWithNibName:@"ComicDetailsViewController" bundle:nil];
comicDetailsViewController.comic = (Comic *)[arrayOfComics objectAtIndex:indexPath.row];
comicDetailsViewController.bLoadPerformances = YES;
[self.navigationController pushViewController:comicDetailsViewController animated:YES];
//[comicDetailsViewController release];
错误不会立即发生,而是在单击omicDetailsViewController中的“上一步”按钮后发生
当我选择tableview行时,下一个视图将加载并正常工作。一旦我完成该视图并单击“后退导航”按钮,程序就会崩溃,并给我exc_bad_访问权限。为什么会这样
编辑:
编辑2:
以下是comicDetailsViewController解除锁定块:
- (void)dealloc {
[comic release];
[xmlParser release];
[webData release];
[currentPerformanceObject release];
[arrayOfPerformances release];
[soapResults release];
[btnPerformances release];
[super dealloc];
}
第376行是webData发布行
编辑3:
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
if(xmlParser)
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[connection release];
[webData release];
}
请给我们看一下堆栈跟踪 但我的初步猜测是,您在
ComicDetailsViewController
类的-(void)dealloc
中做错了什么
请检查一些东西
- 您的
块正常dealloc
- 您没有从其他地方释放
对象或对它的引用comicDetailsViewController
Madhup在弹出视图之前,通过向相应对象发送取消消息来取消NSURLConnection 假设NSURLConnection对象名为asyncConnection:
-(void)viewWillDisappear:(BOOL)animated
[asyncConnection cancel];
}
问题可能仍在您的dealloc中 仅仅因为对象在@interface(.h文件)中,这并不意味着您可以/必须解除锁定变量。我也有这个问题 .h文件
@interface PeopleViewController : UITableViewController {
NSArray *people;
}
@property (nonatomic, retain) NSArray *people;
@end
@implementation PeopleViewController
@synthesize people;
- (void)viewDidLoad {
people = [town.people allObjects];
}
...
- (void)dealloc {
[people release];
}
@end
.m文件
@interface PeopleViewController : UITableViewController {
NSArray *people;
}
@property (nonatomic, retain) NSArray *people;
@end
@implementation PeopleViewController
@synthesize people;
- (void)viewDidLoad {
people = [town.people allObjects];
}
...
- (void)dealloc {
[people release];
}
@end
我不需要释放人员,因为在自定义视图中,我没有增加对象的保留计数,因此在dealloc过程中释放它会导致我的问题。hmm,文本出现了所有有趣的问题。这就是你所说的堆栈跟踪吗?请说明你在
ComicDetailsViewController
类的第376行正在做什么。你确定它在第376行,因为你写的第326行有点混乱。对不起,有点累了。输入错误的326行376在我对原始问题的编辑中,它是dealloc区块的一部分。请检查有关webdata的信息。它有问题。当您拨打网络电话并试图将结果保存到webdata时,是否正在按back键?这就是我猜测的可能是您正在做一些不同的事情。您是对的,我正在运行一个异步NSURLConnection,但是根据代码,didFinishConnection已经运行并且NSXMLParser委托。我不知道为什么WebData仍然在使用…宾果!!!尝试取消所有网络呼叫并重新加载视图。这将解决问题。我不确定如何取消网络呼叫,当我按下后退导航按钮时,会发生此错误。我需要什么事件?我添加了这个,它在取消行exc_bad_access上崩溃。如果在didFailWithError委托和ConnectiondFinishLoading事件中,我将释放连接。