@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有警告标志。问题是螺纹点最终会断裂。这有什么问题吗?
EDIT:
@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
局部声明隐藏实例变量
第一个错误是因为您有一个成员变量声明为
float result;
然后在您的方法中您有一个声明为相同的局部变量。因此局部变量掩盖了成员变量。您应该确保名称不冲突。
实施不完整
第二个错误是因为您在标头中声明了一个方法
-(IBAction)ReturnKeyButton:(id)sender
但然后你实施
-(IBAction)ReturnKeyButton;
这是两种完全不同的方法,其中一种称为ReturnKeyButton
另一个叫做ReturnKeyButton:
请注意名称末尾的冒号。
要解决此问题,只需确保声明匹配即可,例如改变
-(IBAction)ReturnKeyButton;
to -(IBAction)ReturnKeyButton:(id)sender
在实施中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)