使用分段控制作为按钮

时间:2011-09-08 07:19:55

标签: iphone uisegmentedcontrol

我有一个segmentedbar控件。

NSArray *optionsType = [NSArray arrayWithObjects: @"Geopoint", @"Directions", @" ", nil];
    segmentedOption = [[UISegmentedControl alloc] initWithItems:optionsType] ;

我正在使用其中一个分段栏“Geopoint”来显示按下时的子视图(geopointView)。

test = [segmentedOption titleForSegmentAtIndex: [segmentedOption selectedSegmentIndex]];

if([test isEqualToString:@"Geopoint"])
[self.view addsubview:geopointViw];

当“子视图”的必要性结束时,它将从superview中删除。

[geopointview removefromsuperview];

所有这些更改都发生在同一个viewController上。但是现在由于已经按下了分段条“geopoint”,因此在按下另一个分段条之前它不会起作用。

有什么方法可以重置segmentedcontrol吗?

感谢您提前提供任何帮助

2 个答案:

答案 0 :(得分:3)

如果您不希望分段控件显示所选状态,请设置

segmentedControl.momentary = YES;

这使得细分可以作为按钮使用。

答案 1 :(得分:0)

从superview中删除子视图时,使用可以使用segmentedOption.selectedSegmentIndex = 1;

相关问题