2013-10-08 105 views
0

我在我的應用程序中有3個視圖。如何在沒有NavgationController的情況下打開UIViewControllers和Keepstate

我想知道如何正確打開和加載點擊按鈕時的意見。

目前按鈕時從第一視圖點擊我開這樣的

[self dismissViewControllerAnimated:NO completion:nil]; 

    getPLViewController = [[GetPLViewController alloc] initWithNibName:@"GetPLViewController" bundle:nil]; 

    UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow]; 
    [keyWindow addSubview:getProjectListViewController.view]; 

    [self presentViewController:getPLViewController animated:NO completion:nil]; 

而現在的第二視圖,第二視圖打開我開這樣的

currentPLViewController = [[CurrentPLViewController alloc] initWithNibName:@"CurrentPLViewController" bundle:nil]; 


UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow]; 
[keyWindow addSubview: currentPLViewController.view]; 

[self presentViewController:currentPLViewController animated:NO completion:nil]; 

我第三不知道這是否正確了,因爲如果我在前面的視圖加載完成之前嘗試加載視圖,或者沿着這些行加載了視圖,我一直遇到視圖出現問題。

這是我怎麼回去從視圖 - 控制

[self dismissViewControllerAnimated:NO completion:nil]; 

所以我想知道這是做這件事的正確方法嗎?或者,還有更好的方法?

任何幫助,將不勝感激。

回答

1

爲什麼你不在你的根視圖上使用UINavigationController?

您可以隱藏導航欄,它會更乾淨,並且它將與Apple準則相匹配以推送視圖。

假設您使用XIB。 當您從AppDelegate添加您的第一個視圖,添加一個UINavigationController和隱藏這一個:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 
    [navigationController setNavigationBarHidden:YES]; 
    self.window.rootViewController = navigationController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

下一頁您RootViewController(第一視角),你添加一個按鈕並按下SecondViewController

- (IBAction)displaySecondView 
{ 
    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
    [self.navigationController pushViewController:secondViewController animated:YES]; 
} 

SecondViewController推出第三張同樣:

- (IBAction)displayThirdView 
{ 
    ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil]; 
    [self.navigationController thirdViewController animated:YES]; 
} 

and a ac以回到以前的觀點:

- (IBAction)back 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
} 
+0

好吧說瞬間我在第一視圖,但我想跳轉到第三視圖? – HurkNburkS

+0

所以在你的第一個視圖中添加' - (IBAction)displayThirdView') –

+0

好的很酷我想知道這一切,我會讓你知道我是如何得到的:) – HurkNburkS

相關問題