0

I have a tableView that uses the ODRefreshControl. When the view loads everything works fine, the data is loaded into the tableview. But when I reload the tableview using the ODRefreshControl, it crashes.
This is how I'm doing:

-(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];
}

Like you can see I use AFJSONRequestOperation. I have set it to *unsafe_unretained. Because I was thinking that I had the same problem this guys had. But still the app crashes. When you look at my log.

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

Can anybody help me with this?

Community
  • 1
  • 1
Steaphann
  • 2,797
  • 6
  • 50
  • 109

1 Answers1

0

You are declaring the operation as __unsafe_unretained. Nobody is retaining it, so after your call:

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

your operation is probably being released from memory. Why are you declaring it as __unsafe_retained? Declare it as strong (just omit the __unsafe_unretained) and things should work.

Bruno Koga
  • 3,864
  • 2
  • 34
  • 45