2013-05-29 118 views
0

我有一個tableView使用ODRefreshControl。當視圖加載一切正常,數據被加載到tableview。但是當我使用ODRefreshControl重新加載tableview時,它崩潰了。
這是我正在做的:重新加載tableview應用程序崩潰與殭屍異常

-(void)fetchFeed:(NSString *)profile_id andAuthToken:(NSString *)authToken andRefresh:(ODRefreshControl *)refreshControl{ 

    posts = [[NSMutableArray alloc]init]; 
    posts2 = [[NSMutableArray alloc]init]; 
    NSLog(@"here"); 
    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/feed?%@",profile_id,authToken]; 
    NSString* escapedUrlString =[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSURL *url = [NSURL URLWithString:escapedUrlString]; 

    NSURLRequest *request; 
    request = [NSURLRequest requestWithURL:url]; 
    NSLog(@"here2"); 
    AFJSONRequestOperation * __unsafe_unretained operation; 
    [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]; 
    NSLog(@"here4"); 
    operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
     NSLog(@"here3"); 

     _nextUrl = [JSON valueForKeyPath:@"paging.next"]; 
     posts = [[JSON objectForKey:@"data"]mutableCopy ]; 
     for (int i=0;i<posts.count;i++){ 
      NSDictionary *post = [posts objectAtIndex:i]; 
      if(([[post valueForKeyPath:@"from.id"]isEqualToString:@"161595817205146"])&& (!([post valueForKey:@"message"] == NULL))){ 
       [posts2 addObject:post]; 
      } 

     } 
     NSLog(@"posts are %@",posts2); 
     [MBProgressHUD hideHUDForView:self.view animated:YES]; 
     [refreshControl endRefreshing]; 
     [self.tableView reloadData]; 
    } failure:^(NSURLRequest *request ,NSHTTPURLResponse *response ,NSError *error , id JSON){ 
     NSLog(@"error is %@",error); 
    }]; 
    [operation start]; 
} 

就像你可以看到我用AFJSONRequestOperation。我已將其設置爲* unsafe_unretained。因爲我在想我有同樣的問題this guys had. 但是應用程序仍然崩潰。當你看我的日誌。

2013-05-29 08:59:16.237 genkonstage[6892:907] here 
2013-05-29 08:59:16.238 genkonstage[6892:907] here2 
2013-05-29 08:59:16.238 genkonstage[6892:907] here4 
2013-05-29 08:59:16.242 genkonstage[6892:907] T restkit.network:RKObjectRequestOperation.m:172 GET 'https://graph.facebook.com/161595817205146/feed?access_token=467641956646156%7Cel1qACWFQsCG8fLyh4W81aoIZqw': 
request.headers=(null) 
request.body=(null) 
2013-05-29 08:59:16.387 genkonstage[6892:907] *** Terminating app due to uncaught exception of class '_NSZombie_NSException' 
libc++abi.dylib: terminate called throwing an exception 

有人能幫助我嗎?

+0

什麼類的對象是殭屍列表? – Wain

+0

@wain我不知道?我想AFJSONRequestOperation?因爲它在那裏崩潰? – Steaphann

+0

請檢查此鏈接http://stackoverflow.com/questions/11289014/null-libcabi-dylib-terminate-called-throwing-an-exception – iEinstein

回答

0

您正在將操作聲明爲__unsafe_unretained。沒有人保留它,所以在您的電話後:

operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) 

您的操作可能正在從內存中釋放。爲什麼你將它聲明爲__unsafe_retained?聲明它是強大的(只是省略__unsafe_unretained),事情應該起作用。

相關問題