【发布时间】:2014-11-29 23:18:47
【问题描述】:
我需要实现两个分段控件。考虑到两个分段控件的索引,结果会有所不同。考虑到在第一个中,每个索引都有一个 int 固定数(不可变),而第二个控件有一个与每个索引关联的方程。我需要程序了解哪个是两个控件的组合(例如 I = 0 和 II = 1)。 我开发了这段代码,但对我不起作用。
if ((effortSegmented.selectedSegmentIndex ==0) && (styleSegmented.selectedSegmentIndex ==0)) {
float weight_b = [weightTf.text floatValue];
float totalCal = (((704*weight_b)/70.38) - 12);
self.calL.text=[NSString stringWithFormat:@"~%.1f kcal", totalCal];
} else if ((effortSegmented.selectedSegmentIndex==0) && (styleSegmented.selectedSegmentIndex==1)) {
float weight_b = [weightTf.text floatValue];
float totalCal = (((704*weight_b)/70.38)+32);
self.calL.text=[NSString stringWithFormat:@"~%.1f kcal", totalCal];
} else if ((effortSegmented.selectedSegmentIndex==0) && (styleSegmented.selectedSegmentIndex==2)) {
float weight_b = [weightTf.text floatValue];
float totalCal = (((704*weight_b)/70.38)+51);
self.calL.text=[NSString stringWithFormat:@"~%.1f kcal", totalCal];
}
如您所见,[-12, 32, 51] 是与第一个控制索引关联的固定 int。即使我更改控制索引一,运行程序也不会导致标签发生任何变化。不知道去哪里找。
PS 我不能声明标签,因为在
-(void)awakefornib {
[segControl setSegmentedCount:3]
}
我看不到 setSegmentedCount。不在列表中。
谢谢
【问题讨论】:
标签: ios objective-c xcode uisegmentedcontrol