丟失...從陣列中抓取物品時發生崩潰... objective cl
當我按下單元格後嘗試從數組中獲取某個項目(tourresult)時,崩潰。我想從數組中獲取索引,以便我可以創建一個對象並將其傳遞到下一個窗口。看起來我的數組正在某處發佈,但我沒有在它上面設置autorelease,也沒有在任何地方發佈它。我打開殭屍和其他東西,但它不給我任何東西,但「消息發送到釋放實例」,但它不會被釋放...
(PS:這是正確的方式傳輸數據到另一個視圖?)
我有.h文件設置與 NSMutableArray * tourResult; 和財產syntesize在.M
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* loan = [tourResult objectAtIndex:indexPath.row];
Tour *tour = [[[Tour alloc] init] autorelease];
tour.tourID = [loan objectForKey:@"partner_id"];
tour.tourName = [loan objectForKey:@"name"];
tour.tourDescription = [loan objectForKey:@"use"];
tour.tourLat = [[loan objectForKey:@"loan_amount"] floatValue];
tour.tourLon = [[loan objectForKey:@"id"] floatValue];
TableViewDetailViewController *fvController = [[TableViewDetailViewController alloc] initWithNibName:@"TableViewDetailViewController" bundle:[NSBundle mainBundle]];
fvController.tour = tour;
[self.navigationController pushViewController:fvController animated:YES];
[fvController release];
fvController = nil;
}
- (void)fetchedData:(NSData *)responseData
{
//parse out the json data
NSError* error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
tourResult = [[NSMutableArray alloc] init];
tourResult = [json objectForKey:@"loans"];
for (int x = 0;x < [tourResult count];x++)
{
NSDictionary* loan = [tourResult objectAtIndex:x];
[itemsList addObject:[loan objectForKey:@"name"]];
}
[itemsList removeObjectAtIndex:0];
[myTableView reloadData];
}
-(void)loadView
{
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
itemsList = [[NSMutableArray alloc] init];
[itemsList addObject:@"Loading..."];
self.navigationItem.title = @"Tours";
self.view = myTableView;
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: kLatestKivaLoansURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
我知道了。這是第二行。 「ObjectForKey」是一個autorelease對象。我不得不手動「保留」它。謝謝!!! – renevdkooi
如果你想從你的json對象創建一個可變數組,通過「'tourResult = [[NSMutableArray alloc] initWithArray:arrayFromJSON];'」(其中'arrayFromJSON'是一個有效的非零數組, 「'objectForKey'」)。 –