Iphone 将浮动转移到其他类?

Iphone 将浮动转移到其他类?,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我有一个问题,我一直在寻找解决方案,但似乎找不到一个可行的。UserInput.xib、Calculations.h和.m、DataOutput.xib。。。没有用于该计算的.xib UserInput.h DataOutput *dataOutput; UITextField *tf1; UITextField *tf2; UITextField *tf3; @property (nonatomic, retain) DataOutput *dataOutput; @property (no

我有一个问题,我一直在寻找解决方案,但似乎找不到一个可行的。UserInput.xib、Calculations.h和.m、DataOutput.xib。。。没有用于该计算的.xib

UserInput.h

DataOutput *dataOutput;
UITextField *tf1;
UITextField *tf2;
UITextField *tf3;

@property (nonatomic, retain) DataOutput *dataOutput;
@property (nonatomic, retain) IBOutlet UITextField *tf1;
@property (nonatomic, retain) IBOutlet UITextField *tf2;
@property (nonatomic, retain) IBOutlet UITextField *tf3;
Calculations *dataCalc;
UILabel *results1;
UILabel *results2;
UILabel *results3;

@property (nonatomic, retain) Calculations *dataCalc;
@property (nonatomic, retain) IBOutlet UILabel *results1;
@property (nonatomic, retain) IBOutlet UILabel *results2;
@property (nonatomic, retain) IBOutlet UILabel *results3;
NSString *tf1;
NSString *tf2;
NSString *tf3;

NSString *results1;
NSString *results2;
NSString *results3;

float *tempResults1;
float *tempResults2;
float *tempResults3;

@property (nonatomic, retain) NSString *tf1;
@property (nonatomic, retain) NSString *tf2;
@property (nonatomic, retain) NSString *tf3;

@property (nonatomic, retain) NSString *results1;
@property (nonatomic, retain) NSString *results2;
@property (nonatomic, retain) NSString *results3;

- (float)getResults1;
- (float)getResults2;
UserInput.m

@synthesize dataOutput;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

- (IBAction)calculate:(id)sender {
DataOutput *dataOut = [[DataOutput alloc] initWithNibName:@"DataOutput" bundle:nil];

Calculations *calc = [[Calculations alloc] init];
dataOut.dataCalc = calc;
dataOut.dataCalc.tf1 = tf1.text;
dataOut.dataCalc.tf2 = tf2.text;
dataOut.dataCalc.tf3 = tf3.text;

dataOut.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:dataOut animated:YES];
[dataOut release];
@synthesize results1;
@synthesize results2;
@synthesize results3;

- (void)viewDidLoad {
self.results1.text = dataCalc.tf1;
self.results2.text = dataCalc.tf2;
self.results3.text = dataCalc.tf3;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

@synthesize results1;
@synthesize results2;
@synthesize results3;

- (float) getResults1 {
 float temp1 = [tf1 floatValue];
 float temp2 = [tf2 floatValue];

if (temp1 <= 1 && temp2 >= 3) {
  if (temp2 ==10) {tempResults1 = 50;}
  else if (temp2 == 11) {tempResults1 = 52;}
DataOutput.h

DataOutput *dataOutput;
UITextField *tf1;
UITextField *tf2;
UITextField *tf3;

@property (nonatomic, retain) DataOutput *dataOutput;
@property (nonatomic, retain) IBOutlet UITextField *tf1;
@property (nonatomic, retain) IBOutlet UITextField *tf2;
@property (nonatomic, retain) IBOutlet UITextField *tf3;
Calculations *dataCalc;
UILabel *results1;
UILabel *results2;
UILabel *results3;

@property (nonatomic, retain) Calculations *dataCalc;
@property (nonatomic, retain) IBOutlet UILabel *results1;
@property (nonatomic, retain) IBOutlet UILabel *results2;
@property (nonatomic, retain) IBOutlet UILabel *results3;
NSString *tf1;
NSString *tf2;
NSString *tf3;

NSString *results1;
NSString *results2;
NSString *results3;

float *tempResults1;
float *tempResults2;
float *tempResults3;

@property (nonatomic, retain) NSString *tf1;
@property (nonatomic, retain) NSString *tf2;
@property (nonatomic, retain) NSString *tf3;

@property (nonatomic, retain) NSString *results1;
@property (nonatomic, retain) NSString *results2;
@property (nonatomic, retain) NSString *results3;

- (float)getResults1;
- (float)getResults2;
DataOutput.m

@synthesize dataOutput;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

- (IBAction)calculate:(id)sender {
DataOutput *dataOut = [[DataOutput alloc] initWithNibName:@"DataOutput" bundle:nil];

Calculations *calc = [[Calculations alloc] init];
dataOut.dataCalc = calc;
dataOut.dataCalc.tf1 = tf1.text;
dataOut.dataCalc.tf2 = tf2.text;
dataOut.dataCalc.tf3 = tf3.text;

dataOut.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:dataOut animated:YES];
[dataOut release];
@synthesize results1;
@synthesize results2;
@synthesize results3;

- (void)viewDidLoad {
self.results1.text = dataCalc.tf1;
self.results2.text = dataCalc.tf2;
self.results3.text = dataCalc.tf3;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

@synthesize results1;
@synthesize results2;
@synthesize results3;

- (float) getResults1 {
 float temp1 = [tf1 floatValue];
 float temp2 = [tf2 floatValue];

if (temp1 <= 1 && temp2 >= 3) {
  if (temp2 ==10) {tempResults1 = 50;}
  else if (temp2 == 11) {tempResults1 = 52;}
计算。h

DataOutput *dataOutput;
UITextField *tf1;
UITextField *tf2;
UITextField *tf3;

@property (nonatomic, retain) DataOutput *dataOutput;
@property (nonatomic, retain) IBOutlet UITextField *tf1;
@property (nonatomic, retain) IBOutlet UITextField *tf2;
@property (nonatomic, retain) IBOutlet UITextField *tf3;
Calculations *dataCalc;
UILabel *results1;
UILabel *results2;
UILabel *results3;

@property (nonatomic, retain) Calculations *dataCalc;
@property (nonatomic, retain) IBOutlet UILabel *results1;
@property (nonatomic, retain) IBOutlet UILabel *results2;
@property (nonatomic, retain) IBOutlet UILabel *results3;
NSString *tf1;
NSString *tf2;
NSString *tf3;

NSString *results1;
NSString *results2;
NSString *results3;

float *tempResults1;
float *tempResults2;
float *tempResults3;

@property (nonatomic, retain) NSString *tf1;
@property (nonatomic, retain) NSString *tf2;
@property (nonatomic, retain) NSString *tf3;

@property (nonatomic, retain) NSString *results1;
@property (nonatomic, retain) NSString *results2;
@property (nonatomic, retain) NSString *results3;

- (float)getResults1;
- (float)getResults2;
计算.m

@synthesize dataOutput;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

- (IBAction)calculate:(id)sender {
DataOutput *dataOut = [[DataOutput alloc] initWithNibName:@"DataOutput" bundle:nil];

Calculations *calc = [[Calculations alloc] init];
dataOut.dataCalc = calc;
dataOut.dataCalc.tf1 = tf1.text;
dataOut.dataCalc.tf2 = tf2.text;
dataOut.dataCalc.tf3 = tf3.text;

dataOut.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:dataOut animated:YES];
[dataOut release];
@synthesize results1;
@synthesize results2;
@synthesize results3;

- (void)viewDidLoad {
self.results1.text = dataCalc.tf1;
self.results2.text = dataCalc.tf2;
self.results3.text = dataCalc.tf3;
@synthesize tf1;
@synthesize tf2;
@synthesize tf3;

@synthesize results1;
@synthesize results2;
@synthesize results3;

- (float) getResults1 {
 float temp1 = [tf1 floatValue];
 float temp2 = [tf2 floatValue];

if (temp1 <= 1 && temp2 >= 3) {
  if (temp2 ==10) {tempResults1 = 50;}
  else if (temp2 == 11) {tempResults1 = 52;}
@tf1;
@合成tf2;
@合成tf3;
@综合结果1;
@合成结果2;
@综合结果3;
-(浮动)getResults1{
float temp1=[tf1 floatValue];
float temp2=[tf2 floatValue];
如果(temp1=3){
如果(temp2==10){tempResults1=50;}
else如果(temp2==11){tempResults1=52;}
这是我的问题。按照我的设置方式,我可以从userInput中携带数据,抛出计算并在DataOutput的标签中显示它们。但是,当 在我在calculations.h中声明的关于calculations.m的if语句中使用浮点数…我不能携带浮点数(实际的数据计算)转到DataOutput屏幕。在DataOutput上,当我试图通过计算将其设置为浮点值时,它无法识别它,它将识别NSString,但不能识别浮点值。我尝试过将浮点值tempResults1转换为NSString results1,但不断出现错误。我尝试了几种不同的方法,从不同的问题和在这里回答,但不明白为什么它不起作用。有人能帮我吗

我想做的是能够在dataoutput屏幕上显示计算结果

我知道它必须是简单的,也许我做错了什么,或者忽略了我没有做的事情……我不知道,我可以使用一些指导,尽管我知道很多。

if(temp1=3)//这没关系
if (temp1 <= 1 && temp2 >= 3) // this is ok
{
  if (temp2 ==10) { // exact floating point comparisons are dangerous,
                    // and should be avoided. you must rewrite this.
                    // turn up your compiler warnings

        tempResults1 = 50;     // this is not what you think it is.
                               // turn up your compiler warnings. you 
                               // are assigning the address for the
                               // pointer's value. this will lead to a
                               // crash after you use it. what exactly
                               // are you trying to accomplish with this
                               // statement? this must be rewritten.
    } 
  else if (temp2 == 11) {tempResults1 = 52;} // as above
{ 如果(temp2==10){//精确浮点比较是危险的, //应该避免。你必须重写这个。 //打开编译器警告 tempResults1=50;//这不是您所认为的。 //打开你的编译器警告。你可以 //正在为 //指针的值。这将导致 //使用后会崩溃。具体是什么 //你想用这个来完成吗 //声明?这必须重写。 } else如果(temp2==11){tempResults1=52;}//如上所述