私は 2 つのビュー コントローラーを持っています。1 つ目はストーリーボード (これはルート) で、2 つ目はニブレスです。ルート ビュー コントローラーのボタンを押すと、2 番目のコントローラーが呼び出されます。
ここに私の2番目のView Controllerのコードがあります:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UILabel *sampleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0,0,100,100)];
UIImageView * basketItem = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"B.jpg"]];
[self.view addSubview:sampleLabel];
[self.view addSubview:basketItem];
NSLog(@"%@",self.view.subviews);
sampleLabel.text = @"Main Menu";
}
return self;
}
self.view.sebviews クエリは、label オブジェクトと imageView オブジェクトの 2 つのオブジェクトが存在することを示していますが、実際には黒い画面しか表示されません。
移行方法はこちら
- (void)transitionToViewController:(UIViewController *)aViewController
withOptions:(UIViewAnimationOptions)options
{
aViewController.view.frame = self.containerView.bounds;
[UIView transitionWithView:self.containerView
duration:0.65f
options:options
animations:^{
[self.viewController.view removeFromSuperview];
[self.containerView addSubview:aViewController.view];
}
completion:^(BOOL finished){
self.viewController = aViewController;
}];
}