現在、私はindexPathを保存してアクセスしようとしていますが、EXC_BAD_ACCESSエラーを受け取り続けます.xcodeでAnalyzeツールを使用すると、indexPathに格納されている値初期化は決して読み取られません。誰も助けて、ここで何がうまくいかないのか教えてくれますか? 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];
}
方法:
-(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
@ derek.loあなたのクラッシュはまだ同じ場所で発生しますか? '[request.userInfo objectForKey:@" indexPath "];'(おそらくはnilを返すかもしれませんが)アクセスするためにクラッシュするべきではありません。 – trudyscousin
クラッシュが発生した完全な方法で投稿を編集しました。オブジェクトをあるビューから別のビューに移しているのでしょうか? – Apollo