【问题标题】:After reload of tableview app crashes with zombie exception重新加载 tableview 应用程序后因僵尸异常而崩溃
【发布时间】:2013-05-29 23:09:41
【问题描述】:

我有一个使用 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

谁能帮我解决这个问题?

【问题讨论】:

标签: iphone ios objective-c uitableview nszombie


【解决方案1】:

您将操作声明为 __unsafe_unretained。没有人保留它,所以在你打电话后:

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

您的操作可能正在从内存中释放。为什么将其声明为 __unsafe_retained?将其声明为强大(只需省略 __unsafe_unretained),一切都会正常。

【讨论】:

    猜你喜欢
    • 2012-10-25
    • 2015-01-28
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    相关资源
    最近更新 更多