I have a method that creates a segmented control (UISegmentedControl
class) with only two segment "ON" and "OFF". The problem is that I want to initialize the segmented control on the first segment (ON) but any int that I set for the method selectedSegmentIndex
the segmented control still remains on the second segment (OFF). The method is:
itemArray = [NSArray arrayWithObjects: @"On", @"Off", nil];
-(void)wiFiSegmentedControlAtX:(float)x atY:(float)y atWidth:(float)width atHeight:(float)height{
wiFisegmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
wiFisegmentedControl.frame = CGRectMake(x,y,width,height);
wiFisegmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
[wiFisegmentedControl addTarget:self action:@selector(enableWiFi:) forControlEvents: UIControlEventValueChanged];
wiFisegmentedControl.selectedSegmentIndex = 0;
[self.view addSubview:wiFisegmentedControl];
}