Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing a blocked UIAlertView in ViewDidAppear Method on iOS 7 with Xamarin.iOS does not work

if I try to show a blocked AlertView in the ViewDidAppear Method on iOS 7, I won´t be able to dismiss the AlertView. No touch events will reach the AlertView. The Button of the View will be highlighted, but nothing happen. If I run the same code on iOS < 7, it will work fine.

Here is the example code:

    public override void ViewDidAppear(bool animated)
    {
        base.ViewDidAppear(animated);

        var alert = new UIAlertView("Title", "Message", null, "OK");
        alert.Dismissed += (sender, args) => result = true;
        alert.Show();

        while (!result)
            NSRunLoop.Current.RunUntil(NSDate.FromTimeIntervalSinceNow(0.1));
    }

I am using Xamarin.iOS Version 6.4.3.0 with Apple SDK 6.1. I have the same problems with alpha of Xamarin.iOS 6.9.6.0 and Apple SDK 7.0.

Can somebody tell me what the problem is?

Thanks for help.

like image 208
A_vdB Avatar asked Sep 04 '13 07:09

A_vdB


1 Answers

It's not good idea to use NSRunLoop to block UI execution, but certainly there is a better way of doing it.

You can make use async/await pattern to wait for user to press the UIAlertView button. Here's the sample that you can use: https://gist.github.com/prashantvc/6725882

like image 141
Prashant Cholachagudda Avatar answered Nov 15 '22 07:11

Prashant Cholachagudda