私は自分のプロジェクトにUIViewControllerを追加しました。 エラーが発生しました:*キャッチされていない例外 'NSUnknownKeyException'が原因でアプリを終了しています。理由: '[setValue:forUndefinedKey:]:このクラスはキーキャンセルのキー値に符合しません'UIViewControllerにボタンを追加するとエラーが発生しました: 'NSUnknownKeyException'
ここに、ヘッダーファイルと実装ファイルのコードを示します。 アシスタントエディタを使用し、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
SignUpViewController.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
私は、エラーが発生している理由はわかりません。何か案は?
これはInterface Builderの問題です。あなたのビューにボタンを置いたとき、または 'cancel'イベントをその1つに添付しようとしたときに問題が発生しますか? – Dondragmer
ボタンをつけるとき。 – rosst400
イベントをどのように添付していますか? 'Sent Events'、' Touch Up Inside'の 'Connections'インスペクタで' cancel'と言いましたか?あなたの 'cancel'イベントの名前を入力しなければならない場合、おそらく間違った場所にあったでしょう。 [このビデオ](http://www.youtube.com/watch?v=7eFbbvVaYOU)は、特に2:50に役立ちます。 – Dondragmer