我有一个使用ODRefreshControl的tableView。当视图加载一切正常时,数据将加载到tableview中。但是当我使用ODRefreshControl重新加载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 :(得分:0)
您将该操作声明为__unsafe_unretained。没有人保留它,所以在你的电话之后:
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
您的操作可能正在从内存中释放。你为什么把它声明为__unsafe_retained?声明它是强的(只省略__unsafe_unretained)并且事情应该有效。