2011-05-25 123 views
1

時運行下面的代碼給它正確的結果,但去到另一個視圖時,回去的進一步搜索它帶來的「mach_msg_trap」錯誤給錯誤「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]; 
} 

} 

回答

1

你釋放對象,其未被分配:

NSString *str= [[[status objectForKey:@"picture"] valueForKey:@"url"] objectAtIndex:0]; 
[ListPhotos addObject:str]; 
[str release]; 

在這裏,「STR」不應該被釋放,因爲它是一個自動釋放的對象。