小编Jav*_*dez的帖子

sendAsynchronousRequest与drawView上的tableView reloadData延迟

我正在尝试使用iOS5中添加的新sendAsynchronousRequest.我有一个模型类(File),其中一个方法从服务器请求一些数据,然后将此数据传递给创建模型对象的控制器类(FilesController).

模型类有一个方法,下一个代码:

[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    NSArray *decodedResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSArray *files = [self _dictionariesToFiles:decodedResponse];
    handler(files);
}];
Run Code Online (Sandbox Code Playgroud)

控制器类,使用它如下:

[File findAll:conditions completionHandler:^(NSArray *files) {
    dataSource = files;

    NSLog(@"set");

    [self.tableView reloadData];

    NSLog(@"reload");

    activityIndicator.hidden = TRUE;
}];
Run Code Online (Sandbox Code Playgroud)

在控制台中,我可以立即查看NSLogs如何显示"设置"和"重新加载"消息,但表和指示器在几秒(5-10s)过去之前不会改变.

有人知道问题出在哪里?

谢谢.

PD:我用兼容的同步更改了异步请求,然后问题消失了,但是想要使用异步请求.

这是兼容的同步代码:

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSArray *decodedResponse = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
NSArray *files = [self _dictionariesToFiles:decodedResponse];
handler(files);
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios ios5

5
推荐指数
1
解决办法
8804
查看次数

标签 统计

ios ×1

ios5 ×1

objective-c ×1

xcode ×1