2016-07-28 20 views
0

我幾乎閱讀了所有相關文章,但仍然無法取消警報。誰能幫忙?它不應該那麼難...UIAlertViewController的警報模式不能通過添加UIAlertAction來解除

P.S.在defaultAction的回調,我都嘗試:

[self dismissViewControllerAnimated:YES completion:^{ 
                    NSLog(@"ok..."); 
                   }]; 

NSLog(@"ok..."); 

兩個的運氣我的代碼的

#import "ViewController.h" 

@interface ViewController() 
@property (strong, nonatomic) UIAlertController *alert; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidAppear:(BOOL)animated { 
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Reminder" 
                    message:@"" 
                  preferredStyle:UIAlertControllerStyleAlert]; 
    self.alert = alert; 
    self.alert.message = @"You just logged in. The tab will be refreshed"; 
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                  handler:^(UIAlertAction * action) { 
                   [self dismissViewControllerAnimated:YES completion:^{ 
                    NSLog(@"webview is reloading..."); 
                   }]; 

                  }]; 

    [self.alert addAction:defaultAction]; 
    [self presentViewController:self.alert animated:YES completion:nil]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

事實證明這是iOS模擬器的問題。它可以正常工作NSLog(@「ok ...」);設備上的解決方案現在向蘋果提交問題... – lkahtz

+0

我投票結束這個問題作爲題外話,因爲這主要是來自Apple的一個bug。我將盡快與他們一起打開技術支持憑單。在我得到更多信息之前,我現在要關閉這個問題。 – lkahtz

回答

0

關閉。你只需稍作調整即可。

- (void)viewDidAppear:(BOOL)animated { 
    self.alert = [UIAlertController alertControllerWithTitle:@"Reminder" 
                    message:@"You just logged in. The tab will be refreshed" 
                  preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel            handler:^(UIAlertAction * action) { 
//alert dismisses itself 
    }]; 

    [self.alert addAction:defaultAction]; 
    [self presentViewController:self.alert animated:YES completion:nil]; 
} 
1

它會關閉它self.If你

[self dismissViewControllerAnimated:YES completion:^{ 
       NSLog(@"webview is reloading..."); 
      }]; 

使用那麼它將解散當前視圖contrtoller其中報警控制器目前駁回後顯示日誌。

- (void)viewDidAppear:(BOOL)animated 
{ 
     UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Reminder" message:@"" preferredStyle:UIAlertControllerStyleAlert]; 
    self.alert = alert; 
    self.alert.message = @"You just logged in. The tab will be refreshed"; 
       UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) 
      { 
        NSLog(@"Ok button pressed..");  
        NSLog(@"webview is reloading..."); 
     }]; 
    }]; 
    [self.alert addAction:defaultAction]; 
    [self presentViewController:self.alert animated:YES completion:nil]; 
} 
相關問題