iphone - 在rubymotion中按下按钮后如何启动NavigationController

标签 iphone ios objective-c rubymotion

我第一次在 RubyMotion 中尝试一个简单的应用程序。我只是希望能够单击一个按钮,然后启动一个 UINavigationController

步骤: - 用户按下按钮 - 屏幕向左移动并开始新的导航

如果我从第一个 View 本身开始导航,我可以做到这一点,但我希望能够在按下按钮时启动它。

这是我目前的情况

AppDelegate:

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

家庭 Controller :

  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?

结束

最佳答案

尚未测试此代码并根据内存编写,但它应该可以工作。

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

关于iphone - 在rubymotion中按下按钮后如何启动NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15838451/

相关文章:

javascript - iOS 从 Javascript 调用 Objective-C : Some calls are ignored?

iphone - UITableView 不重用单元格,这样做的好例子吗?

iphone - 使用 pathsForResourcesOfType 从组中获取文件

ios - 并非所有输入字段都放大

ios - 将属性从模态视图 Controller 传递给父级

ios - 在 UITableView 中显示 NSMutableArray

objective-c - 如何在 Swift 中返回实例类型

ios - 使用对象对混合数组进行排序

iphone - UIApplication.SharedApplication.TerminateWithSuccess 不存在

ios - 快速 xcode 从导航 Controller 切换到标签栏 Controller 的正确方法