UISegmentedControl:当在工具栏中使用时不触发事件

本文关键字:事件 工具栏 UISegmentedControl | 更新日期: 2023-09-27 18:09:01

Monotouch 4.2 beta版

我把一个UISegmentedControl加到一个UIToolbar。问题是在切换段时没有触发任何事件。我遗漏了什么?

this.oBookmarkSwitch = new UISegmentedControl(new UIImage[] { UIImage.FromFile("./images/index.png"), UIImage.FromFile("./images/bookmark_grey.png") });
this.oBookmarkSwitch.TouchUpInside += delegate {
Console.WriteLine("TOUCHY - never fires");
};
this.oBookmarkSwitch.ValueChanged += delegate {
Console.WriteLine("CHANGE - only fires once when the control is created");
};
this.oBookmarkSwitch.Frame = new RectangleF(0, 0, 100, 30);
this.oBookmarkSwitch.ControlStyle = UISegmentedControlStyle.Bar;
aBarButtons.Add(new UIBarButtonItem(this.oBookmarkSwitch));
oIndexToolbar.SetItems (aBarButtons.ToArray (), false);

UISegmentedControl:当在工具栏中使用时不触发事件

Apple文档对此并不是很清楚,但它指出:

"为分段控件注册目标操作方法uicontroleventvaluechange常量如下所示。(强调我的)

来自Apple和stackoverflow论坛的讨论似乎表明,只支持ValueChange事件——这将匹配运行时行为。也就是说,没有MonoTouch特定的代码用于UISegmentedControl事件(例如,删除对继承事件的支持,如TouchUpInside)。