gpt4 book ai didi

objective-c - 触摸时 UISegmentedControl 索引不更新

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:47:15 25 4
gpt4 key购买 nike

您好,我在更新分段 Controller 的索引时遇到问题。以下代码来自计算类。

 + (NSString *) calculate:(NSString *)height:(NSString *)weight{
double bmiVal = 0;
MBBFirstViewController *fVC;
NSLog(@"%d", [[fVC heightSegment]selectedSegmentIndex]);
NSLog(@"%d", [[fVC weightSegment]selectedSegmentIndex]);
if ([[fVC heightSegment]selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 10.5555;
}else if ([[fVC heightSegment] selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 11.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 12.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 13.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 14.5555;
}else if ([[fVC heightSegment] selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 15.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 16.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 17.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 18.5555;
}
}
NSString *bmiV = [NSString stringWithFormat:@"%.2f",bmiVal];
return bmiV;
}

这段代码来自viewcontroller.m类

- (IBAction)calculateTotal:(id)sender {
NSString *h = [heightField text];
NSString *w = [weightField text];
yourBmiField.text = [calculate yourCalculation:h:w];
}

这是来自viewcontroller.h

 @interface MBBFirstViewController : UIViewController <UITextFieldDelegate>{
UITextField *heightField;
UISegmentedControl *heightSegment;
UITextField *weightField;
UISegmentedControl *weightSegment;
}
@property (strong, nonatomic) IBOutlet UITextField *heightField;
@property (strong, nonatomic) IBOutlet UISegmentedControl *heightSegment;
@property (strong, nonatomic) IBOutlet UITextField *weightField;
@property (strong, nonatomic) IBOutlet UISegmentedControl *weightSegment;
- (IBAction)calculateTotal:(id)sender;
@end

我省略了主要的计算以使其更短。当我运行它时,选定的段始终保持在 0。

谁能看出为什么会这样,如果可能的话告诉我如何解决。

如有任何帮助,我们将不胜感激。

谢谢你

最佳答案

您不是在初始化 FVC viewController 的实例,只是声明它:

改变:

MBBFirstViewController *fVC

收件人:

MBBFirstViewController *fVC = [MBBFirstViewContoller alloc] init];

关于objective-c - 触摸时 UISegmentedControl 索引不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13426569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com