0

So I got this button that with a if statement that pushes to a the StartViewController. I made a NSLog@"transition successful" in the viewDidLoad of this viewcontroller to check if the transition is made.

In the log its showing the transition successful but on the screen not transition is made.

Here is the code:

-(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;

   }


}

and here is the log:

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
Florian Schaal
  • 2,586
  • 3
  • 39
  • 59
  • U r initializing the instance & then removing that view, so I think thats why its printing `NSLog` but not showing you anything on screen! I dnt understand why did u used `removeFromSupreView` & then assignment of its instance to `rootViewController`? Can u explain? – hp iOS Coder Dec 14 '12 at 08:37
  • oh my mistake startViewController should be InitialViewController. Thats the viewcontroller we are in right now. But its still not working if i remove that part. – Florian Schaal Dec 14 '12 at 08:46
  • How can i release the current viewcontroller? – Florian Schaal Dec 14 '12 at 08:48
  • 1
    If you use a UINavigationController you don't have to or want to. Just push a new view onto it. If you want a new UINavigationController I would still not release the old one, since it doesn't take much space and it is easy to switch back to when needed – Roland Keesom Dec 14 '12 at 09:03
  • got it working! StartViewController *startViewController = [[StartViewController alloc] init]; AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; [appDelegate.transitionController transitionToViewController:startViewController withOptions:UIViewAnimationOptionTransitionFlipFromRight]; Thanks for the help! – Florian Schaal Dec 14 '12 at 09:25

2 Answers2

1

New update: this should work:

StartViewController *startViewController = [[StartViewController alloc] init];
    [[UIApplication sharedApplication].delegate.transitionController transitionToViewController:startViewController withOptions:UIViewAnimationOptionTransitionFlipFromRight];
Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
  • oh my mistake startViewController should be InitialViewController. Thats the viewcontroller we are in right now. But its still not working if i remove that part. – Florian Schaal Dec 14 '12 at 08:47
  • i get this error if i try this: /Users/florianschaal/Developer/Janssenpakketapp/Janssenpakketapp/InitialViewController.m:48:54: No visible @interface for 'TransitionController' declares the selector 'initWithRootViewController:' – Florian Schaal Dec 14 '12 at 09:07
  • Then TransitionController is not a UINavigationController. What is it and what is it used for? – Roland Keesom Dec 14 '12 at 09:08
  • its used as UIViewController if im correct. Pick this one up from this post: http://stackoverflow.com/questions/8146253/animate-change-of-view-controllers-without-using-navigation-controller-stack-su sorry kinda beginning IOS programming :P – Florian Schaal Dec 14 '12 at 09:12
  • Are you using some kind of special transition animation? – Roland Keesom Dec 14 '12 at 09:15
  • im using UIViewAnimationOptionTransitionFlipFromRight – Florian Schaal Dec 14 '12 at 09:22
  • got it working! StartViewController *startViewController = [[StartViewController alloc] init]; AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; [appDelegate.transitionController transitionToViewController:startViewController withOptions:UIViewAnimationOptionTransitionFlipFromRight]; Thanks for the help! – Florian Schaal Dec 14 '12 at 09:24
  • Haha I just wrote the same thing :) – Roland Keesom Dec 14 '12 at 09:26
1

you want to to add transition animation then use bellow code...

    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"];
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70