これはとてつもなくばかげた質問ですが、私はそれに問題があります。3 つの UIView を含む .xib を 1 つ作成しました。1 つのグリーン ビュー、1 つのレッド ビュー、および 1 つのブルー ビュー。シミュレーターで実行すると、緑色のビューが表示されます。Green View に 2 つのボタンを配置しました。1 つはレッド ビューを表示し、もう 1 つはブルー ビューを表示します。グリーンビューのコードは次のとおりです。
#import "IDGreenView.h"
#import "IDRedView.h"
#import "IDBlueView.h"
#import "IDGreenView.h"
@interface IDGreenView()
@property (weak, nonatomic) IBOutlet UIButton *RedViewButton;
@property (weak, nonatomic) IBOutlet UIButton *BlueViewButton;
@end
@implementation IDGreenView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (IBAction)showRedView:(id)sender {
[self.window addSubview:[[IDRedView alloc]init]];
}
- (IBAction)showBlueView:(id)sender {
[self.window addSubview:[[IDBlueView alloc]init]];
}
@end
Red Viewのコードは次のとおりです。
#import "IDRedView.h"
@implementation IDRedView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
それが Red View の initWithFrame メソッドに入ることがわかるので、呼び出しに問題がないことがわかります。レッド ビューを表示するにはどうすればよいですか?
ありがとうございました。
--------------------------------------------------更新されたコメント------------------------------------------------ --
いいえ。次のコードをViewControllerに入れましたが、それも機能しませんでした。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.view addSubview:[[IDRedView alloc] initWithFrame:self.view.bounds]];
}
表示されないのはなぜですか?