我已经在我的项目中添加了一个 UIViewController 并且它工作正常,除非我添加了按钮。我收到一个错误:*由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键取消的键值编码。”
这是头文件和实现文件的代码。当我使用助手编辑器和 CTRL 从每个控件拖动到头文件时,所有这些代码都是自动生成的。
SignUpViewController.h:
#import <UIKit/UIKit.h>
@interface SignUpViewController : UIViewController {
IBOutlet UITextField *leader;
IBOutlet UITextField *emailAddress;
IBOutlet UITextField *firstName;
IBOutlet UIScrollView *scrollView;
IBOutlet UITextField *lastName;
}
- (IBAction)cancel:(id)sender;
- (IBAction)signUp:(id)sender;
@end
注册视图控制器.m
#import "SignUpViewController.h"
@interface SignUpViewController ()
@end
@implementation SignUpViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 1000)];
}
- (void)viewDidUnload
{
firstName = nil;
lastName = nil;
emailAddress = nil;
leader = nil;
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)cancel:(id)sender {
}
- (IBAction)signUp:(id)sender {
}
@end
我不确定为什么会发生错误。有任何想法吗?