次にアクセスするView Controllerが「Data Loading」であることをユーザーに警告する必要がある状況があります。
これを FirstViewController ボタン アクションに追加しました。
- (IBAction)showCurl:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Please Wait" message:@"Acquiring data from server" delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[alert show];
SecondViewController *sampleView = [[SecondViewController alloc] init];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
うまくいきません。これは SecondViewController にロードされ、SecondViewController がロードされた後にのみポップアップします。
だから私は SecondViewController 自体を試しました。SecondViewController はリモート サーバーからデータを抽出します。これが、インターネット接続によってはダウンロードに時間がかかる理由です。そこで、関数に UIAlertView を追加することにしました。
- (NSMutableArray*)qBlock{
UIAlertView *alert_initial = [[UIAlertView alloc]initWithTitle:@"Loading" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert_initial show];
NSURL *url = [NSURL URLWithString:@"http://www.somelink.php"];
NSError *error;
NSStringEncoding encoding;
NSString *response = [[NSString alloc] initWithContentsOfURL:url
usedEncoding:&encoding
error:&error];
if (response) {
const char *convert = [response UTF8String];
NSString *responseString = [NSString stringWithUTF8String:convert];
NSMutableArray *sample = [responseString JSONValue];
return sample;
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ALERT" message:@"Internet Connection cannot be established." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
return NULL;
}
これもうまくいきません。さらに、インターネット接続をオフにして、インターネット接続がないことをユーザーに警告する 2 番目のアラートが表示されるかどうかを確認しました。2 番目のアラートも機能しません。