I created a UISegmentedControl through the following snippet.
NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(105, 270, 140, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 0;
[segmentedControl addTarget:self action:@selector(selectWeek:) forControlEvents:UIControlEventValueChanged];
[self.navigationController.view addSubview:segmentedControl];
When I press the button to turn UISegmentedCotrol, it doesn’t work. What could be wrong?
I’m doing segmentedControl.hidden = YES;.
change it to
and make sure
segmentedControl.hidden=NO; when you add it to subview;