丢失...
当我按下一个单元格后尝试从数组(tourresult)中获取一个项目时,它会一直崩溃。我想从数组中获取索引,以便创建一个对象并将其传递到下一个窗口。看起来我的数组正在某个地方发布,但我没有在它上面设置自动释放,也没有在任何地方发布它。我已经打开了 Zombie 和其他东西,但除了“发送到已释放实例的消息”之外,它没有给我任何其他东西,但它没有被释放......
(ps:这是将数据传输到另一个视图的正确方法吗?)
我已经用 NSMutableArray *tourResult; 设置了 .h 文件。.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];
});
}