我有一个非常简单的类(如下所示),但是每次运行它时,它都会返回:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键字段 1 的键值编码。”
我通过以下方式将此 nib 文件绘制到屏幕上:
UIViewController *backViewController = [[UIViewController alloc] initWithNibName:@"myViewBack" bundle:[NSBundle mainBundle]];
UIView *backView = backViewController.view;
[self addSubview:backView];
以下是我设置为文件所有者的类的代码:
。H
#import <Foundation/Foundation.h>
@interface myViewBack : NSObject {
IBOutlet UITextField *field1;
IBOutlet UITextField *field2;
IBOutlet UIView *view;
}
@property (nonatomic, retain) IBOutlet UITextField *field1;
@property (nonatomic, retain) IBOutlet UITextField *field2;
@end
.m
#import "myViewBack"
@implementation myViewBack
@synthesize field1;
@synthesize field2;
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
@end