gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:52:32 24 4
gpt4 key购买 nike

我的应用程序的目标是计算将在文本框中返回的两个字段。不幸的是,我收到有关引用我的 TotalField.text 字段的未知类型字段的错误。我有两种看法。一个是主屏幕,它通过按钮引用第二个 View ,第二个 View 包含我要定位的这些字段和标签。

这是我的代码。

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)];

错误信息:

Unknown type name 'TotalField' and Expected identifier or '('

感谢大家的贡献。

最佳答案

为什么该代码不嵌套在函数内?

将其放入 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) ];

}

关于ios - Xcode 6 中的未知类型名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31260695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com