将视图推送到导航堆栈后释放给我exc_bad_access错误

时间:2010-11-26 04:43:25

标签: iphone objective-c uinavigationcontroller pushviewcontroller

以下代码在tableView didSelectRowAtIndexPath中如果取消注释该版本,我会收到错误:

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_access。这是为什么?

编辑:

#0  0x9682b176 in __kill
#1  0x9682b168 in kill$UNIX2003
#2  0x968bd89d in raise
#3  0x968d39bc in abort
#4  0x968c2164 in szone_error
#5  0x968c21e7 in free_small_botch
#6  0x000a7877 in -[NSConcreteMutableData dealloc]
#7  0x00006433 in -[ComicDetailsViewController dealloc] at ComicDetailsViewController.m:376
#8  0x003cbcc7 in -[UINavigationController setDisappearingViewController:]
#9  0x003c9219 in -[UINavigationController _clearLastOperation]
#10 0x003c9b62 in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#11 0x0055224a in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#12 0x0055338a in -[UINavigationTransitionView _navigationTransitionDidStop]
#13 0x0034829d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#14 0x0034812f in -[UIViewAnimationState animationDidStop:finished:]
#15 0x0244ca28 in run_animation_callbacks
#16 0x0244c8e9 in CA::timer_callback
#17 0x02688d43 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#18 0x0268a384 in __CFRunLoopDoTimer
#19 0x025e6d09 in __CFRunLoopRun
#20 0x025e6280 in CFRunLoopRunSpecific
#21 0x025e61a1 in CFRunLoopRunInMode
#22 0x02f0c2c8 in GSEventRunModal
#23 0x02f0c38d in GSEventRun
#24 0x00326b58 in UIApplicationMain
#25 0x000020f4 in main at main.m:14

编辑2:

这是comicDetailsViewController dealloc块:

- (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];
}

3 个答案:

答案 0 :(得分:1)

请告诉我们堆栈跟踪。

但我最初的猜测是你在- (void) dealloc班的ComicDetailsViewController做错了。

请检查一些事情

  • 您的dealloc区块正常
  • 您不是从其他地方发布comicDetailsViewController对象或对其的引用。

希望这有帮助。

谢谢, Madhup

答案 1 :(得分:0)

在弹出视图之前,通过向相应的对象发送取消消息来取消NSURLConnection。

假设您的NSURLConnection对象名为asyncConnection:

-(void)viewWillDisappear:(BOOL)animated
   [asyncConnection cancel];
}

答案 2 :(得分:0)

问题仍然存在于你的dealloc中。

仅仅因为对象在@interface(.h文件)中,这并不意味着您可以/必须解除变量。我也有这个问题

.h文件

@interface PeopleViewController : UITableViewController {
NSArray *people;
}

@property (nonatomic, retain) NSArray *people;

@end

.m文件

@implementation PeopleViewController

@synthesize people;

- (void)viewDidLoad {
    people = [town.people allObjects];
}

...

- (void)dealloc {
    [people release];
}

@end

我不需要释放人员,因为我在自定义视图中没有增加对象的保留计数,因此在dealloc过程中释放它会导致我的问题。