1

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);
poupou
  • 43,413
  • 6
  • 77
  • 174
Krumelur
  • 32,180
  • 27
  • 124
  • 263

1 Answers1

1

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

Alexandre
  • 13
  • 1
  • 4
poupou
  • 43,413
  • 6
  • 77
  • 174
  • But ValueChanged doesn't fire either when clicking the control. See my example above. It is called once when the control's instance is created but never when touching it. – Krumelur Sep 20 '11 at 12:41
  • poupou, don't bother searching for an answer for now! It works if I do it in a separate project. So it seems to be a side effect of something else. I'll post if I find the issue. Sorry for bothering you. – Krumelur Sep 20 '11 at 13:17