1

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

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

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

这是我到目前为止所拥有的

应用委托:

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

家庭控制器:

  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?

结尾

4

2 回答 2

1

在 appDelegate.m 文件中使用以下 3 个步骤创建基于导航的应用程序

第一步:首先创建一个RootViewController

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

第 2 步:使用 RootviewController 创建导航控制器

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

第 3 步:将 Navigation Controller 添加到 Window 的 Root ViewController

self.window.rootViewController = self.navController;

现在导航按钮点击写这个

创建您想要推送/导航的 viewController 对象

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

使用导航控制器推送该视图

[self.navController pushViewController:startNavigationOne animated:YES];
于 2013-04-05T17:21:38.817 回答
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
于 2013-04-06T05:06:00.653 回答