您可以提供的任何帮助将不胜感激。
我有一个具有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];
}
答案 0 :(得分:12)
您应该使用属性(@property (retain) NSIndexPath *path;
)而不是实例变量,因此当您执行self.path = myIndexPath
时,它会提高保留计数,以便在自动释放IndexPath时不会释放它。