ViewControllers之间的转换不起作用

时间:2012-12-14 08:31:13

标签: iphone objective-c ios uiviewcontroller viewcontroller

所以我得到了这个按钮,其中if语句推送到StartViewController。我在此viewcontroller的NSLog@"transition successful"中创建了一个viewDidLoad来检查是否进行了转换。

在日志中显示转换成功,但在屏幕上没有转换。

以下是代码:

-(IBAction)initialButton:(id)sender {
    NSLog(@"initialButton clicked");

   if([userEmail.text length] <4)
   {
       [WCAlertView showAlertWithTitle:@"Email is empty" message:@"You haven't entered an email yet. Please enter one so we can sent you the shipping labels." customizationBlock:^(WCAlertView *alertView) {
           alertView.style = WCAlertViewStyleBlackHatched;
       } completionBlock:^(NSUInteger buttonIndex, WCAlertView *alertView) {
           if (buttonIndex == 0) {
               NSLog(@"Cancel");
           } else {
               NSLog(@"Ok");
           }
       } cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
   }
   else
   {

       StartViewController *startViewController = [[StartViewController alloc] init];
       self.transitionController = [[[TransitionController alloc] initWithViewController:startViewController] initWithNibName:@"StartViewController" bundle:nil];
       [initialViewController.view removeFromSuperview];
       self.window.rootViewController = self.startViewController;

   }


}

这是日志:

2012-12-14 09:22:55.431 Janssenpakketapp[24165:c07] initialViewController loaded
2012-12-14 09:23:04.021 Janssenpakketapp[24165:c07] initialButton clicked
2012-12-14 09:23:06.116 Janssenpakketapp[24165:c07] Ok
2012-12-14 09:23:11.909 Janssenpakketapp[24165:c07] initialButton clicked
2012-12-14 09:23:11.911 Janssenpakketapp[24165:c07] transition succesful

2 个答案:

答案 0 :(得分:1)

新更新:这应该有效:

StartViewController *startViewController = [[StartViewController alloc] init];
    [[UIApplication sharedApplication].delegate.transitionController transitionToViewController:startViewController withOptions:UIViewAnimationOptionTransitionFlipFromRight];

答案 1 :(得分:1)

你想添加过渡动画然后使用下面的代码...

    StartViewController *startViewController = [[StartViewController alloc] init];
    self.window.rootViewController = self.startViewController;
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFade];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:@"transitionViewAnimation"];