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 <[email protected]> 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 > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch >
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
