2014-03-01 24 views
-3

無論UIViewControllers是模態存在還是iPhone上的UINavigationController推送,堆棧層次結構都會被推送。我怎麼能從另一個UIViewController呈現而不必保持層次結構和能夠使用轉換委託從VC A推UIViewController B,但是釋放VC A一旦VC B可見

VC = UIViewController 

VC A on screen 
VC A --present--> VC B 
VC B on screen 
VC A dealloc 
VC B --present--> VC C 
VC C on screen 
VC B dealloc 
VC C --present--> VC X (or whatever other) 
VC X on screen 
VC C dealloc 

etc... 
+0

從VC A推UIViewController B A =>你只需要解僱或者popViewController – iPatel

+0

Ciao,不要完全理解這個問題,但是有可能這裏有非常聰明的「Deepak解決方案」嗎? http://stackoverflow.com/questions/6065479/better-way-to-select-view-controller-using-poptoviewcontroller-animated/6071463#6071463 – Fattie

回答

0

我只想說:不要那樣做!這只是它應該追加的方式,因爲當你用VC B完成時(當用戶按下上一個按鈕時),你希望VC A回到原來的狀態......

儘管如此,如果你有一個很好的理由要處理爲你解釋,我建議有一個VC主要是將管理所有其他類似:

VC Main : push VC A 
VC A : Request (delegate) VC Main to show VC B 
VC Main : ok, pop VC A + push VC B 
VC B : Request VC Main to show VC X 
VC Main : ok, pop VC B + push VC X 
VC X : Request VC main to show VC A 
VC Main : ok pop VC X + push VC A (VC A is display as default and not as it was on line 2) 
+0

我認爲這是愚蠢的必須這樣做,但我正在付錢這樣做,我試圖找到一種方式。我試圖實現這樣的體系結構,但我需要從一個視圖控制器轉換到另一個視圖控制器,讓圖像變成全屏,然後變成黑白圖像,這只是一個例子! –

0

最好的辦法是使用的UINavigationController委託。例如,您可以創建您自己的UINavigationController的子項。

MyNavigationViewController.h文件:

@interface MyNavigationViewController : UINavigationController 
@end 

MyNavigationViewController.m文件:

@interface MyNavigationViewController() <UINavigationControllerDelegate> 
@end 

@implementation MyNavigationViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.delegate = self; 
    } 
    return self; 
} 

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    if (self.viewControllers.count > 1) { 
     self.viewControllers = @[self.topViewController]; 
    } 
} 

@end 

就用MyNavigationViewController,而不是UINavigationController在你的代碼!

相關問題