0

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];
}
rmaddy
  • 298,130
  • 40
  • 468
  • 517
perascotta
  • 133
  • 9
  • 1
    Maybe you can show the rest of your code? I copy pasted this bit into an empty application and it works fine. If I set index 1 it shows off, if I set 0 it shows on. Also, the segmentedControlStyle is deprecated starting in iOS 7.0 – ophychius May 25 '14 at 11:21
  • All done thanks!! Just removed segmentedControlStyle and all goes perfect! – perascotta May 25 '14 at 12:24

0 Answers0