本文介绍了UISegmentedControl所选索引总是0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UISegmentedControl有6段,我在Interface Builder中创建。我调用以下方法对值改变:
I have a UISegmentedControl that has 6 segments which I created in Interface Builder. I am calling the following method on value changed:
-(IBAction)segmentedChartButtonChanged:(id)sender
{
switch (self.segmentedChartButton.selectedSegmentIndex) {
case 0:
NSLog(@"5d selected. Index: %d", self.segmentedChartButton.selectedSegmentIndex);
break;
case 1:
NSLog(@"3m selected. Index: %d", self.segmentedChartButton.selectedSegmentIndex);
break;
default:
break;
}
}
每当我更改段时, selectedSegmentIndex始终为0
。为什么是这样?
Whenever I change the segments, the selectedSegmentIndex is always 0
. Why is this?
推荐答案
很可能是 IBOutlet
isn连接。检查。您还可以使用传递给方法的 sender
。
It is very likely that the IBOutlet
isn't connected. Check that. You can also use the sender
that is passed to the method.
UISegmentedControl * segmentedControl = (UISegmentedControl *)sender;
switch (segmentedControl.selectedSegmentIndex) {
....
这篇关于UISegmentedControl所选索引总是0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!