Xcode 6中的未知类型名称错误

时间:2015-07-07 05:48:49

标签: ios objective-c c xcode synthesize

我的应用的目标是计算将在文本框中返回的两个字段。不幸的是,我收到有关未知类型字段的错误,指的是我的TotalField.text字段。我有两个观点。一个是主屏幕,它通过一个按钮引用第二个视图,第二个视图包含我试图瞄准的这些字段和标签。

这是我的代码。

ViewController.h

//  SalaryCalcApp
//
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *Total;
@property (strong, nonatomic) IBOutlet UILabel *HourlyRate;
@property (strong, nonatomic) IBOutlet UILabel *NumberOfHours;
@property (nonatomic, strong) UITextField *TotalField;
@property (nonatomic, strong) UITextField *HourlyRateField;
@property (nonatomic, strong) UITextField *NumberOfHoursField;

@end

ViewController.m

//  SalaryCalcApp
//
// 
//

#import "ViewController.h"

@interface ViewController ()

@end



@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@synthesize TotalField;
@synthesize Total;
@synthesize HourlyRate;
@synthesize NumberOfHours;
@synthesize HourlyRateField;
@synthesize NumberOfHoursField;

TotalField.text = [ NSString stringWthFormat:   @"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue)   ];

@end

错误在于此代码:

TotalField.text = [ NSString stringWthFormat:   @"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue)];

错误消息:

  

未知类型名称&#39; TotalField&#39;和预期的标识符或&#39;(&#39;

感谢大家的贡献。

1 个答案:

答案 0 :(得分:1)

为什么代码没有嵌套在函数中?

将它放在viewDidLoad

- (void)viewDidLoad {
    [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
    TotalField.text = [ NSString stringWthFormat:   @"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue)   ];

}