我有一个问题,我一直在寻找解决办法,但似乎找不到一个可行的办法。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;}等等,这是我的problem..with --我的设置方式--我可以从userInput携带数据,抛出计算并在DataOutput上的标签中显示它们。但是,当使用那些if语句中的浮点数时,我在计算中声明了。我无法将浮点数(实际数据计算)传送到DataOutput屏幕上。在DataOutput上,当我试图通过计算将它设置为浮点数时,它会识别NSString,而不会识别浮点数。我已经尝试过将浮点tempResults1转换为NSString results1,并且不断地出现错误。我尝试了几种不同的方法来做这件事,从不同的问题和答案在这里,但不知道为什么它不能工作。有人能帮我吗?
我想要做的是能够在数据输出屏幕上显示计算结果。
我知道这必须很简单,也许我做错了什么或者忽略了一些我没做过的事情.我不知道,虽然我知道那么多,但我需要一点指导。
发布于 2011-02-19 12:56:27
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 abovehttps://stackoverflow.com/questions/5050804
复制相似问题