[MonoTouch] Segmented Control weirdness
Jeff Stedfast
jeff at xamarin.com
Wed Oct 5 10:50:33 EDT 2011
Hi Weiyuent,
I'm not sure if this is the problem, but you probably don't want to be using
a 'using' statement there as it will call Dispose() on the segments control
at the end of the statement.
Hope that helps!
Jeff
On Wed, Oct 5, 2011 at 1:25 AM, weiyuent <spammable at pobox.com> wrote:
> 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.
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111005/7ecb435b/attachment.html
More information about the MonoTouch
mailing list