[MonoTouch] Segmented Control weirdness

weiyuent spammable at pobox.com
Wed Oct 5 01:25:15 EDT 2011


I'm fairly new at this...not sure what I'm doing wrong.

As I build my view controller, I have this:

	var segments = new UISegmentedControl (new System.Drawing.RectangleF (0, 0,
200, 30));
	segments.InsertSegment ("Details", 0, false);
	segments.InsertSegment ("Photos", 1, false);
	segments.ControlStyle = UISegmentedControlStyle.Bar;
	segments.SelectedSegment = 0;
	segments.ValueChanged += HandleFormBtnSegmentsValueChanged;
	var btnSegments = new UIBarButtonItem (segments);

	myViewController.SetToolbarItems (new UIBarButtonItem[]	{ btnSegments },
true);

And here is the code for the handler:

	void HandleFormBtnSegmentsValueChanged (object sender, EventArgs e)	{
		using (UISegmentedControl segments = (UISegmentedControl)sender) {
			Console.WriteLine(segments.SelectedSegment.ToString());
		}
	}

Now here is the output as I alternate clicks on each segment:

	1
	0
	0
	0
	0
	0

After the first two clicks, the value of SelectedSegment never changes. 
Why?

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Segmented-Control-weirdness-tp3873475p3873475.html
Sent from the MonoTouch mailing list archive at Nabble.com.


More information about the MonoTouch mailing list