UISegmentedControl隐藏

时间:2012-01-24 18:49:17

标签: iphone ios visibility uisegmentedcontrol

我通过以下代码段创建了UISegmentedControl

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];

当我按下按钮转动UISegmentedCotrol时,它不起作用。可能有什么不对? 我在做segmentedControl.hidden = YES;

1 个答案:

答案 0 :(得分:0)

[self.navigationController.view addSubview:segmentedControl];

将其更改为

[self.view addSubview:segmentedControl];

并确保segmentedControl.hidden=NO;当你将它添加到子视图;