为什么AFNetworking在iOS中加载数据库这么慢

时间:2015-05-18 16:26:59

标签: ios objective-c uitableview afnetworking

我尝试使用AFNetworking从服务器获取信息并在UITableview中设置数据库,请查看以下代码:

-(void)requestDB:(NSInteger)typeID {
    NSString *picRequestURL = [NSString stringWithFormat:@"%@/infos/list/typeid/%ld",API_URL,(long)typeID];
    NSURL *URL = [NSURL URLWithString:picRequestURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL];
    AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    op.responseSerializer = [AFJSONResponseSerializer serializer];
    op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         if ([[[responseObject objectForKey:@"status"] stringValue] isEqualToString:@"201"]){
             [self setSquaretableData:[responseObject objectForKey:@"list"]];
             if ([self.SquaretableData count] != 0) {
                 [self.tableview reloadData];
             }
         }
         else {

         }
     }
     failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
    [[NSOperationQueue mainQueue] addOperation:op];
}

viewdidload中,我绘制了一个uitableview,并且还调用[self requestDB:1],但是当进入此viewcontroller时,tableview中的所有信息都会加载得太慢,有时候,它无法显示,是我的代码错了,有没有正确的方法来做到这一点,谢谢。

0 个答案:

没有答案