gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:01:14 26 4
gpt4 key购买 nike

我第一次在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com