The delegate is as follows:
public class DoneAlertViewDelegate : UIAlertViewDelegate
{
UINavigationController controller;
EKEventStore store;
EKEvent ekEvent;
public DoneAlertViewDelegate(UINavigationController controller, EKEventStore storeEvent, EKEvent userEvent)
{
this.controller = controller;
store = storeEvent;
ekEvent = userEvent;
}
public override void Clicked (UIAlertView alertview, int buttonIndex)
{
if(buttonIndex == 0)
{
var alert = new UIAlertView("Date Stored", "Date saved in calendar",null,"OK",null);
alert.Show();
SaveEvent();
controller.PopViewControllerAnimated(true);
}
else if(buttonIndex == 1)
{
controller.PopToRootViewController(true);
}
}
public override void Canceled (UIAlertView alertView)
{
}
public void SaveEvent()
{
var err = new NSError();
store.SaveEvent(ekEvent,EKSpan.ThisEvent,out err);
}
}
The problem here is that when I'm debugging, this always crashes the debugger (SIGSEGV) error is called. However, when I simply run the program, it executes as planned. Is this a known issue with monotouc开发者_JS百科h (I'm getting an Objective-C exception) or am I just missing some crucial code to make this work? Thanks in advance!
EDIT: Application Output -
Monotouch.Foundation.MonoTouchException has been thrown "Objective-C exception thrown. Name: NSInvalidArgumentException Reason: - [UITouchData alertView:clickedButtonAtIndex:]: unrecognized selector sent to instance 0xdc614e0
The UIAlertView is probably getting collected. Try making it a class variable.
I had the same problem. It turns out the AlertView DELEGATE was somehow going out of scope. I added it to a temporary variable in my AppDelegate (only as a temporary hack) and it worked. I imagine setting it as a class variable as Mike suggested (but setting the Delegate, not the UIAlertView) should fix it.
精彩评论