NSURLConnection 및 NSHTTPURLResponse를 사용하여 API에서 데이터를 가져 오는 중이지만 데이터가 반환되지 않으면 오류를 표시하는 최선의 방법은 확실하지 않습니다. 지금은 아무 것도 보여주지 않습니다. 기본적으로 UITableView 데이터 소스를 nil로 설정하면됩니다.Fail Safe가있는 UITableView로 데이터를 가져 오는 중
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSURLRequest *seriesReq = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://url/"]];
NSData *responseData = [NSURLConnection sendSynchronousRequest:seriesReq returningResponse:&urlResponse error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
if([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSError *error;
seriesJson = [NSJSONSerialization
JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:&error];
[_seriesTableView reloadData];
}
else {
seriesJson = nil;
}
});
});
내가 설정 더미 데이터 어쩌면 그냥 채우기 seriesJson 생각 한 후, 경우 검사 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
내부를 보여줄 수있을 것이 아니라, 어떤 이유로 그것은 좋은 솔루션으로 나를 공격하지 않습니다.
요청한 데이터가 비어 있거나 사용할 수 없다는 것을 사용자에게 어떻게 표시합니까?