Hello,
I'm quite new to Xamarin.iOS and I'm trying to display an UIAlertView with 3 buttons and write something in the debugger when one of these three buttons is clicked.
I did that :
public partial class HomeScreen : UIViewController
{
public HomeScreen () : base ("HomeScreen", null)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.btn.TouchUpInside += (sender, e) =>
{
using (UIAlertView view = new UIAlertView("Alert", "Click a button", new HomeScreenAlertDelegate(), "OK", "Réessayer", "Annuler"))
{
view.Show();
}
};
}
}
public class HomeScreenAlertDelegate : UIAlertViewDelegate
{
public override void Clicked (UIAlertView alertview, int buttonIndex)
{
Console.WriteLine (buttonIndex.ToString());
}
}
When I click on my button, it displays the alert correctly but when I click on a button, the application crashes. Not all the time. Indeed, sometimes (very rarely), it works correctly but most of the time, I got this error :
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[__NSSetM alertView:clickedButtonAtIndex:]: unrecognized selector sent to instance 0xc032b70 at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 at Test.Application.Main (System.String[] args) [0x00000] in /Users/sebastiensougnez/Desktop/Test/Test/Main.cs:16
Is there an error in how I create/use the delegate ?
Thanks