我有一種情況,我需要提醒用戶訪問的下一個視圖控制器是「數據加載」。插入警報視圖但不起作用
我已將此添加到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;
}
這並不工作過。最後,我試圖關閉互聯網連接,看看是否有第二個警報彈出來提醒用戶沒有互聯網連接。第二次警報不起作用。
爲什麼不使用'UIActivityIndicatorView'來代替?它更加便於用戶使用。 – sooper
你可以指導我如何? –