分段控制有两个段

时间:2014-05-25 10:35:28

标签: ios objective-c uisegmentedcontrol

我有一个创建分段控件(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];
}

0 个答案:

没有答案