因此,目前我试图保存一个indexPath并访问它,但我不断收到EXC_BAD_ACCESS错误,并且当我在xcode中使用分析工具时,它表示在其索引期间存储到我的indexPath的值初始化从不读取。任何人都可以帮助并告诉我这里出了什么问题吗?NSIndexPath内存管理问题
方法来设置indexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSURL *requestURL = [[NSURL alloc] initWithString:@"URL"];
//The request
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:requestURL];
request.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:indexPath,@"indexPath", nil];
[request setDelegate:self];
[request startAsynchronous];
[requestURL release];
[request release];
}
方法来访问indexPath:
-(void)requestFinished:(ASIHTTPRequest *)request{
UIImage *foodImage = [[UIImage alloc] initWithData:[request responseData]];
NSIndexPath *indexPath = [request.userInfo objectForKey:@"indexPath"];
FoodDescription *detailViewController = [[FoodDescription alloc] initWithNibName:@"FoodDescription" bundle:nil];
// pass the food
detailViewController.aFood = [[NSMutableDictionary alloc] initWithDictionary:[_foodArray objectAtIndex:indexPath.row]];
detailViewController.foodPicture = foodImage;
detailViewController.restaurantName = _restaurantName;
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
好吧,你已经解决了indexPath的问题,但由于某种原因它仍然崩溃。我认为它与userInfo字典有关,但是你有没有想过为什么我还会得到EXC_BAD_ACCESS?我将indexPath代码更改为您的建议并摆脱了[indexPath发布] ... – Apollo 2012-04-08 23:04:04
@ derek.lo您的崩溃仍然发生在同一个地方吗?你不应该为了访问'[request.userInfo objectForKey:@“indexPath”];(尽管它可能会返回nil)而崩溃。 – trudyscousin 2012-04-08 23:06:16
我已经编辑我的帖子,发生崩溃的完整方法。这可能是我将物体从一个视图转移到另一个视图的方式吗? – Apollo 2012-04-08 23:47:26