我有一种情况,我需要提醒用户下一个访问的视图控制器是“数据加载”。
我将此添加到 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 从远程服务器提取数据,这就是它需要一段时间才能下载的原因,具体取决于 Internet 连接。所以我决定在函数中添加 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;
}
这也行不通。最重要的是,我尝试关闭互联网连接以查看是否弹出第二个警报以提醒用户没有互联网连接。第二个警报也不起作用。