“本地声明""隐藏实例和不完整的实现 [英] Local declaration of " " hides instance and Incomplete implementation

查看:89
本文介绍了“本地声明""隐藏实例和不完整的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@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 有警告标志.问题是线程点最终会断裂.这有什么问题?

I want to format my text field to a number. This works but it has caution signs over my implantation answer1.text and answer2.text. The problem is that a thread point will break eventually. What is wrong with this?

@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

推荐答案

本地声明隐藏实例变量

第一个错误是因为你有一个成员变量声明为

Local Declaration Hides Instance Variable

The first error is because you have a member variable declared as

float result;

然后在你的方法中你有一个声明为相同的局部变量.因此局部变量掩盖了成员变量.您应该确保名称不会冲突.

and then within your methods you have a local variable declared as the same. Therefore the local variable is masking the member variable. You should make sure the names do not collide.

第二个错误是因为您在标题中声明了一个方法

The second error is because you have a method declared as in your header

-(IBAction)ReturnKeyButton:(id)sender

然后你实施

-(IBAction)ReturnKeyButton;

这是两种完全不同的方法,一种称为 ReturnKeyButton,另一种称为 ReturnKeyButton: 注意名称末尾的冒号.

These are two entirely different methods one is called ReturnKeyButton and the other is called ReturnKeyButton: notice the colon at then end of the name.

要解决这个问题,只需确保声明匹配,例如改变

To fix this just make sure the declarations match e.g. change

-(IBAction)ReturnKeyButton;-(IBAction)ReturnKeyButton:(id)sender 在实现中

这篇关于“本地声明""隐藏实例和不完整的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆