我有一个主窗口(基于窗口的应用程序)和两个不同的UIViewController。我正在调用viewController1而没有任何问题。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}
viewController1上有一个按钮,当我按下按钮我想从mainWindow中删除viewController1并添加viewController2而不使用导航控制器。
任何帮助将不胜感激,非常感谢。
答案 0 :(得分:1)
您可以使用rootViewController
对象的UIWindow
属性。在rootViewController
方法中创建并设置第一个视图控制器为application:didFinishLaunchingWithOptions:
。
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];
}