【问题标题】:Switching between UIViewController在 UIViewController 之间切换
【发布时间】:2011-06-14 22:18:33
【问题描述】:

我有一个主窗口(基于窗口的应用程序)和两个不同的 UIViewController。我调用 viewController1 没有任何问题。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

}

viewController1 上有一个按钮,当我按下按钮时,我想从 mainWindow 中删除 viewController1 并在不使用导航控制器的情况下添加 viewController2。

任何帮助将不胜感激,非常感谢。

【问题讨论】:

    标签: iphone uiview uiviewcontroller


    【解决方案1】:

    您可以使用UIWindow 对象的rootViewController 属性。在application:didFinishLaunchingWithOptions: 方法中创建并设置第一个视图控制器为rootViewController

    self.window.rootViewController = [[[FirsViewController alloc] init] autorelease];
    

    并在按钮点击方法中更改它

    - (IBAction)buttonTapped:(id)sender {
        SecondViewController * viewController = [[[SecondViewController alloc] init] autorelease];
        CGRect frame = viewController.view.frame;
        frame.origin = CGPointMake(0, 20); // To account for the status bar. Otherwise the gap is at the bottom during animation that adjusts after it completes.
        viewController.view.frame = frame;
        [UIView transitionWithView: self.view.window
                          duration: 0.5
                           options: UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{
                            self.view.window.rootViewController = viewController;
                        }
                        completion: NULL];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多