我有一個警報視圖,當沒有互聯網連接時彈出。當有互聯網連接時,我有辦法禁用它...。 工作代碼:禁用警報視圖連接到互聯網時
-(void)reachabilityChanged:(NSNotification*)note
{
Reachability * reach = [note object];
if([reach isReachable])
{
notificationLabel.text = @"Notification Says Reachable";
NSLog(@"Internet is Up");
}
else
{
notificationLabel.text = @"Notification Says Unreachable";
NSLog(@"Internet is Down");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please connect to Internet"
message:nil
delegate:self
cancelButtonTitle:nil
otherButtonTitle:nil
[alert show];
}
}
-(void)dismissAlert:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
您的簡化版,代碼甚至顯示警報視圖...。 –
我想在有互聯網連接時禁用警報視圖...。 –
如果您已經注意到,我在代碼的末尾添加了一種方法,可以讓您關閉警報。在if語句中(所以當有互聯網連接時),就會調用該方法。你在頭文件中實現了'UIAlertViewDelegate'嗎? – Mat