2011-03-08 89 views
1

我已經回到hello world tutorials試圖做到這一點。我似乎無法理解這一點,但它應該如此簡單。使用UINavigationBar在視圖之間切換

我想要在右側有一個按鈕的UINavigationBar。當用戶按下此按鈕時,它將通過滑動到邊的動畫將它們帶到第二個視圖,並且在這個新視圖上,導航欄顯示前一個視圖的後退按鈕。

我怎麼能得到這個發生?我不能爲我的生活弄清楚。有沒有一個教程在哪裏可以找到它?我找不到一個。

回答

0

在按鈕操作(選擇器)使用下面的消息上self.navigationController

pushViewController:secondViewController animated:YES 

編輯:創建的UINavigationController如下:

UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 

然後設置右按鈕根據需要索林在他的回答中建議。並且在我的原始答案中已經發布了在self.navigationController上使用pushViewController:animated:消息。希望能幫助到你。 rootViewController是您希望作爲導航堆棧上的第一個視圖推送的視圖控制器。

+0

解決了這個問題 - 謝謝。我留下的問題是如何製作導航控制器,以及如何確保它出現在這些視圖上?我對此毫不知情。 – Andrew 2011-03-08 19:46:11

+0

看到我上面的編輯 – Bourne 2011-03-08 20:42:11

3

您應該以UIViewController作爲根創建一個UINavigationController。在UIViewController中,你應該設置欄右鍵。你應該有一些與此類似:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
         initWithTitle: @"Next" 
         style:UIBarButtonItemStyleDone 
         target:self 
         action:@selector(nextPage:)] 
         autorelease]; 

當你觸摸按鈕的方法下一頁:將被調用,將執行新的視圖的推動。

-(void)nextPage:(id)sender 
{ 
    UIViewController *secondViewController = [[UIViewController alloc] init]; 
    [self.navigationController pushViewController:secondViewController animated:YES]; 
    [secondViewController release]; 
} 

這裏是使用UINavigationControllerhere兩個部分教程是爲UINavigationController的(真的很有用)的官方文檔。