我遇到了无法将来自 Viewcontroller 的 UItextfields 的值设置为另一个从这些值进行计算的类的问题。
@interface InitialViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *phValue;
@property (weak, nonatomic) IBOutlet UITextField *pco2Value;
@property (weak, nonatomic) IBOutlet UITextField *hco3Value;
@property (weak, nonatomic) IBOutlet UITextField *sodiumValue;
@property (weak, nonatomic) IBOutlet UITextField *chlorideValue;
@property (nonatomic,retain)NSDecimalNumber* ph;
@property (nonatomic,retain) NSDecimalNumber* pco2;
@property (nonatomic,retain)NSDecimalNumber* hco3;
@property (nonatomic,retain)NSDecimalNumber* sodium;
@property (nonatomic,retain)NSDecimalNumber* chloride;
- (IBAction)analyseValues:(UIButton *)sender;
@end
在实施中
-(void)values{
[self setPh:[[NSDecimalNumber alloc] initWithFloat:phValue.text.floatValue ]];
[self setPco2:[[NSDecimalNumber alloc] initWithFloat:pco2Value.text.floatValue]];
[self setHco3:[[NSDecimalNumber alloc ] initWithFloat:hco3Value.text.floatValue]];
[self setSodium:[[NSDecimalNumber alloc] initWithFloat:sodiumValue.text.floatValue] ];
[self setChloride:[[NSDecimalNumber alloc] initWithFloat:chlorideValue.text.floatValue] ];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self values];}
然后我有另一个类,它采用这些值,但是在运行它运行的程序时,它确实分配了从 initialViewController 中获取的值。
#import <Foundation/Foundation.h>
#import "InitialViewController.h"
@interface AcidBaseCalculations : NSObject
@property (nonatomic) float ph;
@property (nonatomic) float pco2;
@property (nonatomic) float chloride;
@property (nonatomic) float sodium;
@property (nonatomic) float hco3;
@implementation AcidBaseCalculations
@synthesize ph,pco2,chloride,hco3,sodium;
-(void)calculations{
InitialViewController *bvc = [[InitialViewController alloc] init];
ph = bvc.ph.floatValue ;
pco2 = bvc.pco2.floatValue;
// these values are not being set although the program runs successfully
hco3 = bvc.hco3.floatValue;
sodium = bvc.sodium.floatValue;
chloride = bvc.chloride.floatValue;
我想在这里使用这些新值并在这个类中执行一些逻辑操作。