Writing handler for UIAlertAction

后端 未结 9 942
北恋
北恋 2020-11-28 05:10

I\'m presenting a UIAlertView to the user and I can\'t figure out how to write the handler. This is my attempt:

let alert = UIAlertController(ti         


        
9条回答
  •  囚心锁ツ
    2020-11-28 05:14

    1. In Swift

      let alertController = UIAlertController(title:"Title", message: "Message", preferredStyle:.alert)
      
      let Action = UIAlertAction.init(title: "Ok", style: .default) { (UIAlertAction) in
          // Write Your code Here
      }
      
      alertController.addAction(Action)
      self.present(alertController, animated: true, completion: nil)
      
    2. In Objective C

      UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
      
      UIAlertAction *OK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
      {
      }];
      
      [alertController addAction:OK];
      
      [self presentViewController:alertController animated:YES completion:nil];
      

提交回复
热议问题