运行以下代码时,它会给出正确的结果但是当转到另一个视图并返回进一步搜索时会出现'mach_msg_trap'错误
- (void)viewWillAppear:(BOOL)animated {
AppDeleget= [[UIApplication sharedApplication] delegate];
ProcessView *Process=[[ProcessView alloc] init];
[Process SearchProperty:AppDeleget.PropertyURL page:AppDeleget.Page];
[Process release];
for(NSDictionary *status in AppDeleget.statuses)
{
NSMutableString *pic_string = [[NSMutableString alloc] initWithFormat:@"%@",[status objectForKey:@"picture"]];
if([pic_string isEqualToString:@""])
{
[ListPhotos addObject:@"NA"];
}
else
{
NSString *str= [[[status objectForKey:@"picture"] valueForKey:@"url"] objectAtIndex:0];
[ListPhotos addObject:str];
[str release];
}
}
[NSThread detachNewThreadSelector:@selector(LoadImage) toTarget:self withObject:nil];
[AppDeleget.MyProgressView stopAnimating];
[AppDeleget.Progress removeFromSuperview];
[super viewWillAppear:animated];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableCell *cell = (TableCell *)[TableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// NSString *bedsbaths=[NSString stringWithFormat:@"Beds:%@ Baths:%@",[[AppDeleget.statuses valueForKey:@"beds"] objectAtIndex:indexPath.row],[[AppDeleget.statuses valueForKey:@"baths"] objectAtIndex:indexPath.row]];
cell.mlsno.text=[[AppDeleget.statuses valueForKey:@"mlsno"] objectAtIndex:indexPath.row];
cell.price.text=[[AppDeleget.statuses valueForKey:@"price"] objectAtIndex:indexPath.row];
cell.address.text=[[AppDeleget.statuses valueForKey:@"address"] objectAtIndex:indexPath.row];
// cell.bedsbaths.text=bedsbaths;
cell.bedsbaths.text=[[AppDeleget.statuses valueForKey:@"dispDetails"] objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
-(void)LoadImage
{
for(int x=0;x<[ListPhotos count];x++)
{
if ([ListPhotos objectAtIndex:x] == @"NA")
{
UIImage *img = [UIImage imageNamed:@"No_image.png"];
[self performSelectorOnMainThread:@selector(downloadDone:) withObject:img waitUntilDone:NO];
}
else
{
NSData *imageData =[ListPhotos objectAtIndex:x];
id path = imageData;
NSURL *url = [NSURL URLWithString:path];
NSLog(@"%@",url);
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
[self performSelectorOnMainThread:@selector(downloadDone:) withObject:img waitUntilDone:NO];
}
}
}
-(void)downloadDone:(UIImage*)img {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:count inSection:0];
if(img == nil)
{
TableCell *cell = (TableCell *)[TableView cellForRowAtIndexPath:indexPath];
cell.myImageView.image=[UIImage imageNamed:@"No_image.png"];
++count;
[TableView reloadData];
}
else
{
TableCell *cell = (TableCell *)[TableView cellForRowAtIndexPath:indexPath];
cell.myImageView.image=img;
++count;
[TableView reloadData];
}
}
答案 0 :(得分:1)
您正在发布未分配的对象:
NSString *str= [[[status objectForKey:@"picture"] valueForKey:@"url"] objectAtIndex:0];
[ListPhotos addObject:str];
[str release];
这里,'str'不应该被释放,因为它是一个自动释放的对象。