2012-06-18 37 views
0

是否可以在didFinishWithResult中顯示模態視圖控制器?無法在didFinishWithResult中顯示模態視圖控制器

我有一個iPad應用程序,有3個視圖主頁,開始和登錄。啓動和登錄模式視圖可以在主視圖中使用啓動和登錄按鈕啓動。

如果單擊登錄按鈕,在登錄視圖中成功登錄操作(didFinishWithResult)後,我可以關閉登錄視圖,但我無法啓動啓動視圖。但控制停留在主視圖上。

上述情況我沒有收到任何錯誤。

Appdeligate.m:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

HomeViewController * homeview=[[HomeViewController alloc] init]; 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeview]; 

self.rootViewController = navigationController; 
[navigationController setNavigationBarHidden:YES]; 
self.rootViewController.view.frame = [[UIScreen mainScreen] applicationFrame]; 
[self.window addSubview:self.rootViewController.view]; 
[window makeKeyAndVisible]; 

下面是其中存在的登錄模式的看法

呈現登錄模式的看法

LoginViewController * vc1 = [LoginViewController loginViewControllerWithNavBar:YES]; 
vc1.boxLoginDelegate = self; 
[self presentModalViewController:vc1 animated:YES]; 

主視圖的方法注意:LoginVeiwController是Modal v由HomeViewController提供 的控制器。通過如下撤消LoginVeiwController 來啓動/呈現另一個模式 視圖控制器(啓動控制器)是否正確。因爲每當LoginVeiwController駁回控制停留回到HomeVeiwContrller,而不是啓動/呈現StartViewController:

主頁查看

下面是主頁視圖的方法,將駁回對成功登錄登錄視圖並嘗試啓動開始視圖。

- (void)loginViewController:(LoginViewController *)loginViewController didFinishWithResult:(LoginResult)result { 
    [self dismissModalViewControllerAnimated:YES]; 

    startview = [[[startViewController alloc] init] autorelease]; 
    [self.navigationController setNavigationBarHidden:YES]; 
    [self presentModalViewController:startview animated:YES]; 

} 

如果我直接出示StartView上按一下按鈕,它很好地啓動,但不能在didFinishWithResult

+0

' - (無效)loginViewController:(LoginViewController *)loginViewController didFinishWithResult:(LoginResult)result'似乎是一個委託方法。你是代表嗎? – CodaFi

+0

是的,它是一個代表方法 –

+0

雖然這並沒有回答我的第二個問題。你是這種方法的調用者的代表嗎? – CodaFi

回答

0

我想這是關於動畫。而此前控制器解僱,

[self presentModalViewController:startview animated:YES]; 

被調用。

您可以通過將動畫設置爲NO來驗證我的猜測。或直接使用我的建議來查看它是否有效。

如果我是正確的,你可以將它們設置回YES。 此外,而不是直接調用

[self presentModalViewController:startview animated:YES]; 

你可以試試:

[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(showController) userInfo:nil repeats:No]; 

- (void)showController { 
    [self presentModalViewController:startview animated:YES]; 
} 

編輯:

我終於找到了我怎麼之前解決這個類似的問題:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{  
    [UIView animateWithDuration:0.5 
        animations:^{ 
          [self dismissModalViewControllerAnimated:YES]; 
        } 
       completion:^(BOOL finished) { 
        NSURL *path = [info objectForKey:@"UIImagePickerControllerMediaURL"]; 
        VideoConfirmViewController *videoConfirmCon = [[VideoConfirmViewController alloc]initWithFileURL:path]; 
        [self presentModalViewController:videoConfirmCon animated:YES]; 
       } 
]; 
} 
+0

即使這並沒有幫助 –

+0

也許你可以再次嘗試更高的時間間隔。 0.5可能不足以解僱。 – TedCheng

+0

即使我將時間間隔增加到6.0f,登錄模式視圖也會被取消並停留在主視圖上。沒有導航到StartView。請重新檢查我編輯過的問題。 –

0

試試這個。我認爲這對你會有所幫助。

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    HomeViewController * homeview=[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeview]; 
    [self.window addSubview:navigationController.view]; 
    [window makeKeyAndVisible]; 
return YES: 
+0

我的代碼和你的代碼似乎在Appdelegate.m是相同的,請你指出我需要改變 –

0

你需要重組這一行代碼[self dismissModalViewControllerAnimated:YES];之所以被解僱時被調用,你控制的鬆散self背景,因此線[self presentModalViewController:startview animated:YES];沒有顯示任何控制器還。 快速評論解僱線,看看你自己。

+0

這使得登錄模式視圖只停留在屏幕上,不變化甚至發生在後面 –

0

使用這一行,當你currentViewController DissMiss然後嘗試婁代碼...

[self performSelector:@selector(PresentView) withObject:nil afterDelay:0.2]; 

-(void)PresentView 
{ 
    [self.navigationController presentModalViewController:startview animated:YES]; 
} 

希望,這幫助你.... :)

0

如果你不需要用很投緣舊版本的IOS,最好是使用

-(void)presentViewControllerAnimated:completion: 
-(void)dismissViewControllerAnimated:completion: 

,而不是

-(void)presentModalViewController:animated: 
-(void)dismissModalViewController:animated: 

在這種情況下

- (void)loginViewController:(LoginViewController *)loginViewController didFinishWithResult:(LoginResult)result 
{ 
    [self dismissViewControllerAnimated:YES completion: ^{ 
     startview = [[[startViewController alloc] init] autorelease]; 
     [self.navigationController setNavigationBarHidden:YES]; 
     [self.presentingViewController presentViewControllerAnimated:YES completion:NULL]; 

    }]; 
} 
相關問題