基本的に、2 つのビュー コントローラーを 1 つのコントローラーに追加しようとしています。
「MultipleViews」というビューベースのアプリケーションを作成しました。その後、2 つのコントローラー クラス "RedView.h" と "BlueView.h" を独自の xib と共に追加します。メソッドによって、両方のコントローラーのビューを「MutipleViewsViewController」に追加できます[self.view addSubview:red.view]
。両方のビューが正しく表示されます。問題は、赤と青のコントローラーにボタンを追加するときです。ボタンをクリックするたびにunrecognized selector sent to instance
、ボタンとその機能を適切にリンクしているにもかかわらず、それが表示されます。ここで何か不足していますか?
コードは次のとおりです。
MultipleViewsViewController.h
#import <UIKit/UIKit.h>
@interface MutipleViewsViewController : UIViewController {
}
@end
MutipleViewsViewController.m
-
(void)viewDidLoad {
[super viewDidLoad];
RedView *red = [[RedView alloc]init];
red.view.frame = CGRectMake(0, 0, 320, 240);
[self.view addSubview:red.view];
BlueView *blue = [[BlueView alloc]init];
blue.view.frame = CGRectMake(0, 240, 320, 240);
[self.view addSubview:blue.view];
}
RedView.h
#import <UIKit/UIKit.h>
@interface RedView : UIViewController {
}
-(IBAction)buttonPressed;
@end
BlueView.h
#import <UIKit/UIKit.h>
@interface BlueView : UIViewController {
}
-(IBAction)buttonPressed;
@end
ボタンは、IB を介して buttonPressed メソッドにリンクされています。赤いビューのボタンをクリックすると表示されるメッセージは次のとおりです。
MutipleViews[1865:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RedView buttonPressed]: unrecognized selector sent to instance 0x4e12500'
先がはっきりしなくてすみません。