Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从UIViewController调用tabbarviewcontroller?_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 如何从UIViewController调用tabbarviewcontroller?

Iphone 如何从UIViewController调用tabbarviewcontroller?,iphone,objective-c,ios,Iphone,Objective C,Ios,我有一个基于tabbar的应用程序,有三个选项卡。现在,当设备从纵向旋转到横向时,应加载不同的UIViewController,当应用程序模式从横向更改回纵向模式时,应再次显示tabbar控制器。如何做到这一点?我想你可以用以下方法来解决这个问题。由于有两个不同的ViewController位于同一层次上,因此有必要使用一个ViewController,它管理这两个ViewController并根据方向显示相应的ViewController 肖像画 窗口 MyRootViewControll

我有一个基于tabbar的应用程序,有三个选项卡。现在,当设备从纵向旋转到横向时,应加载不同的UIViewController,当应用程序模式从横向更改回纵向模式时,应再次显示tabbar控制器。如何做到这一点?

我想你可以用以下方法来解决这个问题。由于有两个不同的ViewController位于同一层次上,因此有必要使用一个ViewController,它管理这两个ViewController并根据方向显示相应的ViewController

肖像画

  • 窗口
    • MyRootViewController
      UIViewController
      子类)
      • MyTabBarViewController
        UITabBarViewController
        子类)
景观

  • 窗口
    • MyRootViewController
      UIViewController
      子类)
      • MyViewController
        UIViewController
        子类)
现在,您的
MyRootViewController
类检测到任何旋转(请参阅
UIViewController
文档),并将其视图更改为两个viewcontroller中的任意一个:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    // Set the view to the corresponding ViewController (Assuming they were already initialized)
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
        self.view = self.myTabBarViewController.view;
    } else {
        self.view = self.myPortraitViewController.view;
    }
}
您还应确保在启动/重新激活应用程序时显示正确的ViewController。为此,可以在MyRootViewController类中使用以下方法:

- (void)viewWillAppear:(BOOL)animated;

我希望这对您有所帮助

您所说的“它将打开一个
UIViewController
”是什么意思?请注意,
UIViewController
是uitabarcontroller和UINavigationController等的超类。打开意味着加载从UIViewController继承的另一个视图控制器