I can't seem to capture the click event on a UIBarButtonItem in my UIToolbar. I can see the click animation when i'm clicking on the button, but the code won't fire. I've tried hooking it up through the constructor, manually adding the event listener, and using delegates as the handlers.. none of it works. Am i missing something here?
using MonoTouch.CoreGraphics;
using MonoTouch.UIKit;
using System;
using System.Drawing;
namespace Company.Mobile.Challenge
{
public class DatePickerView : UIView
{
public delegate void OnDoneEventHandler(object sender, DateEventArgs e);
public event OnDoneEventHandler onDone;
UIDatePicker picker;
UIToolbar toolbar;
UIBarButtonItem doneBtn;
public DatePickerView(UIDatePickerMode aMode, RectangleF aRect)
: base(aRect)
{
AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
toolbar = new UIToolbar(new RectangleF(0, 0, Frame.Width, Globals.ControlHeights.UIToolbarPortrait))
{
BarStyle = UIBarStyle.Black
};
doneBtn = new UIBarButtonItem(UIBarButtonSystemItem.Done, OnDoneClicked);
toolbar.Items = new UIBarButtonItem[] { doneBtn };
AddSubview(toolbar);
picker = new UIDatePicker()
{
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
Mode = aMode
};
picker.Frame = new RectangleF(0, Globals.ControlHeights.UIToolbarPortrait, Frame.Width, picker.Frame.Height);
AddSubview(picker);
}
void OnDoneClicked(object sender, EventArgs args)
{
Console.WriteLine("This isn't firing...");
}
}
}