Mrw*_*lfy 17 xcode uisegmentedcontrol ios
我有一个带有两个段(索引:0和1)的UISegmentedControl,我试图以编程方式重置为0.当我运行下面的命令时,它不会按预期将段索引重置为0.相反,它突出显示段索引1.
[seg setSelectedSegmentIndex:0];
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我记录所选的段时,它返回0.
NSLog(@"seg setSelectedSegmentIndex %d", seg.selectedSegmentIndex);
Run Code Online (Sandbox Code Playgroud)
同样奇怪的是,在运行后setSelectedSegmentIndex:0我无法通过触摸手动重新选择段0,它似乎被锁定到段1,直到我点击1,其中它正常工作.
这是按钮的设置:
itemArray = [NSMutableArray arrayWithObjects: @"Zero", @"One", nil];
seg = [[UISegmentedControl alloc] initWithItems:itemArray];
[seg setFrame:segRect];
seg.segmentedControlStyle = UISegmentedControlStyleBar;
seg.momentary = NO;
[seg addTarget:self action:@selector(someAction:) forControlEvents: UIControlEventValueChanged];
[mainView addSubview:seg];
Run Code Online (Sandbox Code Playgroud)
注意:要重述我试图用这个问题完成的事情:我想动态地通过变量设置UISegmentedControl的选定索引,获得适当的视觉反馈,并检查方法中的选定索引,以根据所选择的方式发生某些事情指数.请参阅下面的答案以获得解决方案.
小智 28
在某一方面的变化 viewDidLoad:
[seg setSelectedSegmentIndex:index];
Run Code Online (Sandbox Code Playgroud)
你改变使用索引值作为你的愿望.
| 归档时间: |
|
| 查看次数: |
38011 次 |
| 最近记录: |