开发者

transferring floats to a different class?

开发者 https://www.devze.com 2023-02-12 05:31 出处:网络
I have a problem that I have been searching for a solution for but can\'t seem to find one that works. UserInput.xib , Calculations.h & .m ,DataOutput.xib ... there is no .xib for that calculation

I have a problem that I have been searching for a solution for but can't seem to find one that works. UserInput.xib , Calculations.h & .m ,DataOutput.xib ... there is no .xib for that calculations.

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 (no开发者_StackOverflow社区natomic, 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;}

etc etc etc ok here is my problem..with the way I have things setup I can carry data from the userInput, threw Calculations and display them in a label on the DataOutput. BUT, when using the floats in those if statements on calculations.m that I declared in calculations.h... I can't carry the floats (the actual data calculations) over to the DataOutput screen. on DataOutput when I try to set it a float from calculations it doesn't recognize it, it will recognize the NSString but not the float. I have tried converting float tempResults1 to NSString results1 and i keep getting errors. I have tried several different ways to go about doing this from different questions and answers on here but can't figure out why it wont work. can anyone help me with this?

What I want to do is to be able to display results from the calculations on the dataoutput screen.

I know it has to be something simple, maybe I'm doing something wrong or overlooking looking something I didn't do ... I don't know, I could use a little guidance though I know that much.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消