我正在使用这个块方法从服务器加载我的数据......
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[myString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:urlRequest
queue:queue
completionHandler: ^( NSURLResponse *response,
NSData *data,
NSError *error)
{
[[mySingleton dictionaryUserDetail] removeAllObjects];
[[mySingleton arrayUserDetail] removeAllObjects];
if ([data length] > 0 && error == nil) // no error and received data back
{
NSError* error;
NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
[mySingleton setDictionaryUserDetail:[myDic mutableCopy]];
NSArray *myArray = [myDic objectForKey:@"searchResults"];
[mySingleton setArrayUserDetail:[myArray mutableCopy]];
dispatch_async(dispatch_get_main_queue(), ^{
[self userDetailComplete];
});
} else if
([data length] == 0 && error == nil) // no error and did not receive data back
{
dispatch_async(dispatch_get_main_queue(), ^{
[self serverError];
});
} else if
(error != nil) // error
{
dispatch_async(dispatch_get_main_queue(), ^{
[self serverError];
});
}
}];
我希望能够向用户显示进度条,而不仅仅是一个微调器。如果我使用代表我假设我可以使用 NSURLConnectionDelegate
connection:didReceiveData:
但我不知道如何用块来做到这一点。有人有一些天才的见解吗?