2012-02-08 42 views
3

我目前正在爲我的公司開發iPhone應用程序,我遇到了一個奇怪的事情。presentModalViewController - ViewController自動消失後呈現

我查看數字體系是這樣的:

包含5個選項卡包含一個UINavigationController每個標籤的UITabBarController。 到目前爲止,一切都很完美。

現在我想使用的代碼此線對 的UITabBarController經由presentModalViewController方法呈現模態的視圖控制器:

-(void)callFilterOptions 
{ 
    FilterOptionsView *filterView = [[FilterOptionsView alloc] init]; 
    [filterView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self.tabBarController presentModalViewController:filterView animated:TRUE]; 
} 

的FilterOptionsView是含有隻不過是一個黑色背景在 時刻正常的UIViewController 。

會發生什麼情況是視圖呈現,幾秒鐘後神祕消失。 這是怎麼回事?在沒有點我打電話dismissModalViewController方法。

我在展示mailcomposer時已經遇到了這個問題。

問候, 弗洛裏安

+0

嘗試更改self.tabBarController for [self.view presentModalViewController:filterView animated:TRUE]; – oriolpons 2012-02-08 15:07:49

+0

發生同樣的錯誤。我無法從視圖中呈現模式視圖控制器,所以我嘗試[self presentModalViewController:filterView animated:TRUE]; – user1197467 2012-02-08 15:12:38

+0

你使用ARC嗎?嘗試使您的filterView作爲類變量 – Chakalaka 2012-02-08 15:22:11

回答

0
UINavigationController *myNavController = [self navigationController]; 
[myNavController presentModalViewController:filterView animated:TRUE]; 

或更好的方法是:

UIApplication *myApp = [UIApplication sharedApplication]; 
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate; 
[appDelegate.tabBarController presentModalViewController:filterView animated:YES]; 

辭退:

UIApplication *myApp = [UIApplication sharedApplication]; 
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate; 
[appDelegate.tabBarController dismissModalViewControllerAnimated:YES]; 

附:我建議不命名視圖控制器「filterView」它會更好地命名爲「filterViewController」

+0

可悲的是不適合我:< – user1197467 2012-02-08 15:37:31

+0

感謝您的答案,但我找到了解決方案。 [self.navigationController.tabBarController presentModalViewController:filterView animated:TRUE]; 這樣做的技巧... – user1197467 2012-02-08 15:39:01

+0

在你的結構中的callFilterOptions方法?在視圖控制器? – ader 2012-02-08 15:40:11

相關問題