UISegmentedControl:在UIToolbar中使用时不会触发任何事件

时间:2011-09-20 09:59:23

标签: c# cocoa-touch events xamarin.ios uisegmentedcontrol

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);

1 个答案:

答案 0 :(得分:1)

Apple documentation对此并不十分清楚,但它声明:

“您使用以下命令为分段控件注册 目标操作方法 UIControlEventValueChanged常量如下所示。“(强调我的)

来自Applestackoverflow论坛的讨论似乎也表明只支持 ValueChange 事件 - 这与运行时行为相匹配。即UISegmentedControl事件没有MonoTouch特定代码(例如,删除对 TouchUpInside 等继承事件的支持。)