2012-07-18 5 views
0

ViewController에서 가져온 값을 UItextfields에서 가져온 값을 해당 값의 계산을 수행하는 다른 클래스로 설정할 수없는 문제가 있습니다. 구현값을 UIViewController에서 계산할 다른 클래스로 가져온 값을 설정할 수 없습니다.

-(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];} 

에서

@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 

그때 나는이 값을 사용합니다 다른 클래스를 가지고 있지만, 프로그램을 실행에 그것을 실행하지만 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; 

여기서 새 값을 사용하고이 클래스에서 일부 논리 연산을 수행하고 싶습니다.

답변

1

이 줄 새로운 InitialViewController 만드는 :

InitialViewController *bvc = [[InitialViewController alloc] init]; 

그것은보다 diffrent 인스턴스를 다른/원래 InitialViewController

당신에게 어느 속성

@property(nonatomic,strong)InitialViewController myInitialVC; 

을 확인해야 AcidBaseCalculations을 할당/초기화 할 때이 속성을 설정하십시오. 우리는 당신은 당신이

AcidBaseCalculations에 INITING/계산하고 ALLOC 동안을 설정하려는 모든 변수에 대한 특성을해야

관련 문제