UISegmentedControl:在 UIToolbar 中使用时不会触发任何事件
Monotouch 4.2 测试版。
我正在将 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);
Monotouch 4.2 beta.
I'm adding a UISegmentedControl
to a UIToolbar
.
The problem is that none of the events fire when switching segments. What am I missing here?
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Apple 文档对此不是很清楚,但它指出:
“您注册使用分段控件的目标操作方法
UIControlEventValueChanged 常量如下所示。”(强调我的)
还有 Apple 的讨论< /a> 和 stackoverflow 论坛似乎表明只有 ValueChange 事件是支持 - 这将与运行时行为相匹配,即 UISegmentedControl 事件没有 MonoTouch 特定代码(例如,删除对 TouchUpInside 等继承事件的支持)。
Apple documentation is not very clear on this but it state that:
"You register the target-action methods for a segmented control using the
UIControlEventValueChanged constant as shown below." (emphasis mine)
Also discussions from Apple and stackoverflow forums seems to indicate that only the ValueChange event is supported - which would match the runtime behavior. I.e. there's no MonoTouch specific code for the UISegmentedControl events (e.g. to remove support for inherited events like TouchUpInside).