我第一次在RubyMotion中尝试一个简单的应用程序。我只是希望能够点击按钮,然后启动UINavigationController
步骤: - 用户按下按钮 - 屏幕向左移动并开始新导航
如果我从第一个视图本身开始导航,但我希望能够在按钮按下时启动它,我可以做得很好。
这是我到目前为止所拥有的
的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?
端
答案 0 :(得分:1)
创建appliation基于导航的应用程序使用appDelegate.m文件中的以下3个步骤
步骤1:首先创建一个RootViewController
ViewController *rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
步骤2:使用RootviewController创建导航控制器
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
步骤3:将导航控制器添加到Window的Root ViewController
self.window.rootViewController = self.navController;
现在导航开启按钮点击此处
创建要推送/导航的viewController对象
ViewController *startNavigationOne = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
使用导航控制器推送该视图
[self.navController pushViewController:startNavigationOne animated:YES];
答案 1 :(得分: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