활동 표시기를 시작하는 데 여러 가지 방법을 검토했지만 올바르게 동기화하는 것이 다소 어려워 보입니다. 아래 코드에서는 아무 것도 깨지지 않지만 마지막 순간까지 Activity 모니터 아이콘 (throbber)이 나타나지 않아 다음보기로 전환됩니다.UIActivityMonitor Out of Sync
사용자가 UITable 내의 요소 중 하나를 두드리면 JSON 응답을 얻고 사용자가 다음보기로 이동합니다. 완벽하게 작동합니다. ActivityIndicator가 앞에서 설명한 것처럼 늦게 나타나는 것을 제외하고는.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = spinner;
[spinner startAnimating];
timer = [NSTimer scheduledTimerWithTimeInterval:3.0/1.0 target:self selector:@selector(loading) userInfo:nil repeats:YES];
//Go to the next view
if ([cell.textLabel.text isEqualToString:@"Vatsim Pilots"]) {
VatsimViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"newview"];
[self.navigationController pushViewController:detail animated:YES];
}
}
NSStimer 기능을 사용하려고했지만 분명히 작동하지 않습니다. 다른 사람들이 JSON 서비스를 사용하지는 않지만 본 적이 있습니다. 나는 데이터가 어디서 왔는지는 중요하지 않다고 생각했을 것이다. 그리고 데이터가 준비되었을 때만 신경 써야 할 것이다.
미리 감사드립니다.
: https://github.com/mattneub/ Programming-iOS-Book-Examples/tree/master/iOS7bookExamples/bk2ch12p564timeConsumingNavigation – matt
감사합니다. Matt, 필자는 동기 네트워킹이 아닌 어딘가를 읽었다. 즉 NSData * 데이터 = [NSURLConnection sendSynchronousRequest : req returningResponse : nil error : & error]; if (error) { NSLog (@ "% @", [error localizedDescription]); – Jeremy
BTW 훌륭한 사례! – Jeremy