将花车转移到另一个班级?

时间:2011-02-19 12:36:50

标签: 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 (nonatomic, retain) IBOutlet UITextField *tf1;
@property (nonatomic, retain) IBOutlet UITextField *tf2;
@property (nonatomic, retain) IBOutlet UITextField *tf3;

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

DataOutput.h

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;

DataOutput.m

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

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

Calculations.h

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;

Calculations.m

@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;}

等等等确定这里是我的问题..我的设置方式我可以从userInput携带数据,抛出计算并将其显示在DataOutput上的标签中。但当 使用我在calculate.h中声明的那些if语句中的浮点数...我不能将浮点数(实际数据计算)传递到DataOutput屏幕。在DataOutput上,当我尝试将它设置为计算器中的浮点数时 认识到它,它会识别NSString而不是浮动。我已经尝试将float tempResults1转换为NSString results1并且我不断收到错误。我已经尝试了几种不同的方法来解决这里从不同的问题和答案,但无法弄清楚为什么它不会工作。任何人都可以帮我这个吗?

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

我知道它必须是简单的东西,也许我做错了一些或忽略看起来我没做的事... ... idk,我可以使用一点指导,虽然我知道那么多哈哈。

1 个答案:

答案 0 :(得分:2)

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