Objective c DIDSELECTROWATINDEXC\u访问错误\u在didSelectRowAtIndexPath中
我已按以下方式覆盖了我的Objective c DIDSELECTROWATINDEXC\u访问错误\u在didSelectRowAtIndexPath中,objective-c,ios,uitableview,exc-bad-access,didselectrowatindexpath,Objective C,Ios,Uitableview,Exc Bad Access,Didselectrowatindexpath,我已按以下方式覆盖了我的UITableViewControllerdidSelectRowAtIndexPath方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { PhotoListViewController *photosViewController = [[PhotoListViewController alloc] initWithSty
UITableViewController
didSelectRowAtIndexPath
方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PhotoListViewController *photosViewController = [[PhotoListViewController alloc] initWithStyle:UITableViewStylePlain];
NSLog(@"Let's see what we got %d", [[fetchedResultsController fetchedObjects] count]);
Person *person = [fetchedResultsController objectAtIndexPath:indexPath];
photosViewController.person = person;
photosViewController.title = [person.name stringByAppendingString:@"'s Photos"];
[self.navigationController pushViewController:photosViewController animated:YES];
[photosViewController release];
}
每当我试图访问fetchedResultsController时,我都会得到崩溃,我在这里设置它:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person = %@", person];
fetchedResultsController = [[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate];
}
return self;
}
我只在我的
dealloc
方法中释放它似乎在调用didSelectRowAtIndexPath方法之前,您的自动释放池已经耗尽。您是否尝试像这样保留fetchedResultsController:
fetchedResultsController = [[[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate] retain];
似乎在调用DidSelectRowatineXpath方法之前,您的自动释放池已耗尽。您是否尝试像这样保留fetchedResultsController:
fetchedResultsController = [[[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate] retain];
请发布任何相关的车祸信息。控制台输出、崩溃日志,并确保NSZombieEnabled没有崩溃信息,它只是在我的main中的这一行int retVal=UIApplicationMain(argc、argv、nil、nil)上停止;然后说EXC_BAD_access你能告诉我如何设置NSZombieEnabled吗?好的,我设置了NSZombieEnabled,但是我的fetchedObjects不在那里似乎,让我进一步检查一下问题只是没有保留fetchedResultsController,但是NSZombieEnabled将帮助你更快地发现类似的问题。请发布任何相关的车祸信息。控制台输出、崩溃日志,并确保NSZombieEnabled没有崩溃信息,它只是在我的main中的这一行int retVal=UIApplicationMain(argc、argv、nil、nil)上停止;然后说EXC_BAD_access你能告诉我如何设置NSZombieEnabled吗?好的,我设置了NSZombieEnabled,但是我的fetchedObjects不在那里似乎,让我进一步检查一下问题只是没有保留fetchedResultsController,但是NSZombieEnabled将帮助你更快地发现类似的问题。如果您检查我发布的第二段代码,我会在initWithStyle方法中执行此操作。这里的键是要保留的调用,除非您保留它,否则您的fetchedResultsController不能保证在init方法之外使用足够长的时间。我想将属性设置为(非原子,保留)您是否在指定
self
之前不使用该属性self.fetchedResultsController
将不要求您保留,因为它将使用属性而不是像您现在这样的实例变量。如果您检查我发布的第二段代码,我会在initWithStyle方法中执行此操作。这里的键是要保留的调用,除非您保留fetchedResultsController,否则无法保证它在init方法之外有足够的使用寿命。我认为将属性设置为(非原子,retain)可以确保您不使用该属性,除非您指定self
self.fetchedResultsController
将不要求您保留,因为它将使用属性而不是像您现在这样的实例变量。