开发者

Switching between UIViewController

I have a main window (Window based application) and two different UIViewController. i am calling viewController1 in without any problem.

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

}

there is a button on viewController1, when i press to button I want to remove viewController1 from mainWindow and a开发者_Go百科dd viewController2 without using navigation controller.

any help would be appreciated, many thanks.


You can use the rootViewController property of the UIWindow object. Create and set the first view controller as the rootViewController in application:didFinishLaunchingWithOptions: method.

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

And change it in the button tap method

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜