@implementation ViewController
-(IBAction)ReturnKeyButton:(id)sender {
[sender resignFirstResponder];
}
@synthesize torque, horsepower, rpm, rpmf2;
-(IBAction)Operation1:(id)sender {
float result = 2 * 3.14 *([torque.text floatValue] * [rpm.text floatValue]) / 33000;
answer1.text = [[NSString alloc] initWithFormat:@"%2.f", result];
}
-(IBAction)Operation2:(id)sender {
float result = 2 * 3.14 * ([horsepower.text floatValue] * [rpmf2.text floatValue]) / 33000;
answer2.text = [[NSString alloc] initWithFormat:@"%2.f", result];
}
我想将我的文本字段格式化为一个数字。这可行,但它对我的植入 answer1.text 和 answer2.text 有警告标志。问题是线程点最终会断裂。这有什么问题?
编辑:
@interface ViewController : UIViewController {
float result;
IBOutlet UILabel *answer1;
IBOutlet UILabel *answer2;
IBOutlet UITextField *torque;
IBOutlet UITextField *rpm;
IBOutlet UITextField *horsepower;
IBOutlet UITextField *rpmf2;
int currentOperation1;
float torque1;
float rpm1;
float horsepower1;
float rpm1f2;
float answer5;
}
-(IBAction)Operation1:(id)sender;
-(IBAction)Operation2:(id)sender;
@property(nonatomic, retain) IBOutlet UITextField *torque;
@property(nonatomic, retain) IBOutlet UITextField *rpm;
@property(nonatomic, retain) IBOutlet UITextField *horsepower;
@property(nonatomic, retain) IBOutlet UITextField *rpmf2;
-(IBAction)ReturnKeyButton;
@end