I have a UISegmentedControl
UIBarButtonItem *flex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]autorelease];
bottomSegmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
[bottomSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"messages.png"] atIndex:0 animated:YES];
[bottomSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"news.png"] atIndex:1 animated:YES];
[bottomSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"chart.png"] atIndex:2 animated:YES];
//bottomSegmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Messages",@"News",@"Chart", nil]];
//bottomSegmentedControl.tintColor = [UIColor blackColor];
[bottomSegmentedControl addTarget:self action:@selector(segmentedControlChanged:)forControlEvents:UIControlEventValueChanged];
bottomSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
bottomSegmentedControl.frame = CGRectMake(0,0,300,30);
bottomSegmentedControl.momentary = NO;
[bottomSegmentedControl setSelectedSegmentIndex:0];
UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:bottomSegmentedControl];
When I step through the program [bottomSegmentedControl setSelectedSegmentIndex:0]; does not trigger a UIControlEventValueChanged event which is where I do some stuff in segmentedControlChanged:
This used to work in iOS 4.3 but not in iOS5. How can I resolve this?
This seems to be a known issue. It’s not clear whether Apple considers the new behavior to be a feature or a bug.