[英]Unknown type name error in Xcode 6
我的应用程序的目标是计算两个将在文本框中返回的字段。 不幸的是,我收到有关我的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)];
错误信息:
未知类型名称“ TotalField”和期望的标识符或“(”
谢谢大家的贡献。
为什么该代码未嵌套在函数中?
将其放入您的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) ];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.