[英]Unknown type name error in Xcode 6
The goal of my app is to calculate two fields that will return in a text box. 我的应用程序的目标是计算两个将在文本框中返回的字段。 Unfortunately I'm receiving an error regarding with unknown type field referring to my TotalField.text field.
不幸的是,我收到有关我的TotalField.text字段的未知类型字段的错误。 I have two views.
我有两种看法。 One is the home screen which refers to the second view through a button and the second view contains these fields and labels that I'm trying to target.
一个是主屏幕,它通过按钮引用第二个视图,第二个视图包含我要定位的这些字段和标签。
This is my code. 这是我的代码。
ViewController.h 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 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
The error resides in this code: 错误驻留在以下代码中:
TotalField.text = [ NSString stringWthFormat: @"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue)];
Error Message: 错误信息:
Unknown type name 'TotalField' and Expected identifier or '('
未知类型名称“ TotalField”和期望的标识符或“(”
Thank you everyone for your contributions. 谢谢大家的贡献。
Why is that code not nested inside a function? 为什么该代码未嵌套在函数中?
Put it inside your viewDidLoad 将其放入您的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.