我有 2 个视图控制器,第一个是故事板(这是根),第二个是 nibles。当我按下根视图控制器中的按钮时,它应该调用第二个控制器。
这是我的第二个视图控制器的代码:
- (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 查询显示存在 2 个对象标签和 imageView 对象,但实际上我只看到黑屏。
这是过渡方法
- (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;
}];
}