NSIndexPath:发送到解除分配的实例的消息

时间:2010-11-23 04:06:27

标签: iphone transitions nsindexpath

您可以提供的任何帮助将不胜感激。

我有一个具有tableView,detailView,flipView和moreDetail View的应用程序。它很好地通过过渡直到第26个元素。当我点击导航到flip和moreDetailView的按钮时,应用程序崩溃了。

我收到错误消息:[NSIndexPath row] message sent to deallocated instance

我想我可能会多次调用indexPath,但是为什么一切都运行良好直到第25个元素然后停止工作? NSIndexPath是如何解除分配的?我从来没有解除分配。

如果您知道,请帮忙。谢谢!!!

Xcode说问题就在这里:

@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 个答案:

答案 0 :(得分:12)

您应该使用属性(@property (retain) NSIndexPath *path;)而不是实例变量,因此当您执行self.path = myIndexPath时,它会提高保留计数,以便在自动释放IndexPath时不会释放它。