2012-12-14 35 views
0

所以我得到這個按鈕,if聲明推到StartViewController。我在這個視圖控制器的viewDidLoad中做了一個[email protected]"transition successful"來檢查是否進行了轉換。ViewControllers之間的轉換不工作

在日誌中顯示轉換成功,但在屏幕上沒有轉換。

下面是代碼:

-(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 
+0

初始化實例然後刪除那個視圖,所以我認爲這就是爲什麼它的打印「NSLog」,但沒有在屏幕上顯示任何東西!我不明白爲什麼你使用'removeFromSupreView'然後將其實例賦值給'rootViewController'?你能解釋一下嗎? –

+0

哦,我的錯誤startViewController應該是InitialViewController。這就是我們現在正在使用的視圖控制器。但是如果我刪除那部分,它仍然不起作用。 –

+0

我如何釋放當前的視圖控制器? –

回答

1

新的更新:這應該工作:

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

哦,我的錯誤startViewController應該是InitialViewController。這就是我們現在正在使用的視圖控制器。但是如果我刪除那部分,它仍然不起作用。 /Users/florianschaal/Developer/Janssenpakketapp/Janssenpakketapp/InitialViewController.m:48:54: –

+0

我已經更新了我的答案 –

+0

我,如果我嘗試這樣得到這個錯誤「TransitionController」不可見@interface聲明選擇「initWithRootViewController: ' –

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"]; 
相關問題