2013-04-05 40 views
1

我在RubyMotion第一次嘗試一個簡單的應用程序。我只是希望能夠點擊一個按鈕,然後開始UINavigationControllerruby​​motion按鈕按下後如何啓動NavigationController

步驟: - 用戶按下一個按鍵 - 屏幕移動到左,新的導航開始

我可以,如果我開始這樣做精從第一個視圖本身導航,但我希望能夠按下按鈕啓動它。

這裏是我迄今爲止

的AppDelegate:

#below commented line starts the navigation from the first view 
#navController = UINavigationController.alloc.initWithRootViewController(HomeController.alloc.init) 
@window.rootViewController = HomeController.alloc.init 
true 

的HomeController:

def viewDidLoad 
    self.title = "ONE" 
    button = UIButton.buttonWithType(UIButtonTypeRoundedRect) 
    button.frame = [[15,300], [280,50]] 
    button.setTitle("Move to next view", forState: UIControlStateNormal) 
    button.addTarget(self, 
        action: "startNavigationOne:", 
        forControlEvents: UIControlEventTouchUpInside) 

    view.addSubview(button) 
    end 

    def startNavigationOne (sender) 
    #what can I do here to start the navigation? 

回答

1

沒有測試碼並從內存中寫入,但它應該工作。

def startNavigationOne (sender) 
    # Create your next controller and its navigation controller 
    next_controller = UIViewController.alloc.initWithNibname(nil, bundle: nil) 
    nav = UINavigationController.alloc.initWithRootViewController(next_controller) 

    # Now set it as the root view controller 
    UIApplication.sharedApplication.delegate.window.rootViewController = nav 

    # The current UIViewController will be deallocated when this method exits 
end 
1

創建appliation娜基於vigation應用程序中使用以下3個步驟在appDelegate.m文件

步驟1:首先創建一個RootViewController的

ViewController *rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 

步驟2:用RootViewController的

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; 

第3步創建導航控制器:添加導航控制器到窗口的根視圖控制器

self.window.rootViewController = self.navController; 

我們導航按鈕上點擊寫這個

創建要推/導航

ViewController *startNavigationOne = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 

把你的viewController對象視圖中使用導航控制器

[self.navController pushViewController:startNavigationOne animated:YES]; 
+0

在第3步,當我運行應用程序時,它已經在屏幕頂部有一個欄,表示它已經有導航。我不'想要這個。我希望只有當我點擊按鈕 – Anthony

+0

纔會出現在頂部的欄,然後你需要寫這個[self.navigationController setNavigationBarHidden:YES animated:YES];顯示並[self.navigationController setNavigationBarHidden:NO animated:YES];隱藏 –

+0

由於這不是Ruby代碼,它可以很容易地翻譯成紅寶石。關於這篇文章的好消息是self.pushViewController方法的正確用法。 –

相關問題