NSIndexPath: message sent to deallocated instance

寵の児 提交于 2019-12-12 09:23:34

问题


Any help you can offer would be appreciated.

I have a app that has a tableView, detailView, flipView, and moreDetail View. It is fine moving through the transitions until the 26th element. The app crashes when I hit buttons that navigate to the flip and moreDetailView.

I am given the error Msg: [NSIndexPath row] message sent to deallocated instance.

I think I may be calling the indexPath too many times, but why does everything work well up until the 25th element and then stop working? How did the NSIndexPath get deallocated? I never deallocated it.

If you know, please help. Thank you!!!

Xcode says the problem is here:

@implementation produceView aka *detailView*

- (IBAction)showInfo {

        FlippedProduceView *fView = [[FlippedProduceView alloc]initWithIndexPath:index];
    fView.flipDelegate = self;


    fView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:fView animated:YES];
         [fView release]; 

}


 - (IBAction) buttonPushed:(id)sender

{

    picView *pictureView = [[picView alloc]initWithIndexPath:index];


    pictureView.picDelegate = self;
    pictureView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;     

    [self presentModalViewController:pictureView animated:YES];
        [pictureView release];
}

-(id)initWithIndexPath:(NSIndexPath *)myIndexPath {   
if (self == [super init]) {
            path = myIndexPath;

    }
    return self;

}

@implementation picView aka *moreDetailView*

- (void)viewDidLoad {
    RipeGuideAppDelegate *AppDelegate = (RipeGuideAppDelegate *)[[UIApplication sharedApplication] delegate];
    self.picViewArray = AppDelegate.arrayProduceInfo;

    NSMutableDictionary *dictionary = [picViewArray objectAtIndex:path.row];
}

@implementation FlippedProduceView aka *flipView*


- (id)initWithIndexPath:(NSIndexPath *)myIndexPath {
    if (self == [super init]) {
        indexes = myIndexPath;
    }
    return self;
}

- (void)viewDidLoad {
    RipeGuideAppDelegate *AppDelegate = (RipeGuideAppDelegate *)[[UIApplication sharedApplication] delegate];
    self.flipViewArray = AppDelegate.arrayProduceInfo;

    NSMutableDictionary *dictionary = [flipViewArray objectAtIndex:indexes.row];
}

回答1:


You should use properties (@property (retain) NSIndexPath *path;) instead of instance variables, so then when you do self.path = myIndexPath then it raises the retain count so it won't be deallocated when IndexPath is autoreleased.



来源:https://stackoverflow.com/questions/4252681/nsindexpath-message-sent-to-deallocated-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!