我有一个创建分段控件(UISegmentedControl
类)的方法,只有两个段" ON"和"关闭"。问题是我想在第一个段(ON)上初始化分段控件,但是我为方法selectedSegmentIndex
设置的任何int分段控件仍然保留在第二个段(OFF)上。方法是:
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];
}