LoginSignup
4
3

More than 5 years have passed since last update.

Xamarin.iOSでアラートを表示する方法

Posted at

Xamarin.iOSでアラートを表示する方法です。iOS8からUIAlertViewがdepreciatedになっているので、UIAlertControllerを使用します。

アラートスタイルやアラートを表示したときのアクションは任意で変えられますが、アラートだけの例を示します。UIViewControllerを継承したサブクラスで使ってください。

try
{
}
catch (Exception e)
{
    var alert = UIAlertController.Create("ここは任意のタイトル", e.Message, UIAlertControllerStyle.Alert);
    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
    PresentViewController(alert, true, null);
}

エラーのアラートだけではなくて、普通のダイアログとしても使えます。アラートのスタイルを変える場合はUIAlertControllerStyleを、アクションスタイルを変える場合はUIAlertActionStyleを変えてください。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3