如何在 Xamarin.iOS 应用中创建导航? [英] How to create navigation in a Xamarin.iOS app?

查看:13
本文介绍了如何在 Xamarin.iOS 应用中创建导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于使用 Xamarin.Forms.我在 XAML 或 C# 中创建了一个页面并导航到它.但现在这是我第一次尝试创建不是 Xamarin.Forms 的 iOS 应用.我正在 Windows PC 上从 Visual Studio 执行此操作(当然连接到 Mac).我发现ViewController 类似于Xamarin.Forms Page.但是我如何创建另一个页面并告诉应用程序导航到它?我要创建另一个 UIViewController 吗?如果是这样,我如何告诉一个导航到另一个?

I'm used to working with Xamarin.Forms. I create a Page in XAML or C# and navigate to it. But now it's my first time trying to create an iOS app that's not Xamarin.Forms. I'm doing it from Visual Studio on a Windows PC (connected to a Mac, of course). I've figured out that the ViewController is something like a Xamarin.Forms Page. But how do I create another page and tell the app to navigate to it? Do I create another UIViewController? And if so, how do I tell one to navigate to another?

我找到的都是使用其他 IDE 的教程.我如何在 Visual Studio 中而不是for Mac"中执行此操作?

All I've found are tutorials that use other IDEs. How do I do it in Visual Studio not "for Mac"?

此外,似乎一种方法(唯一的方法?)是使用称为故事板的东西.但是,在 VS 中,当单击解决方案资源管理器中的故事板时,它会开始连接到 mac"(它已经连接到),并且有一个持续不断的进度条.它永远不会加载.所以如果有没有故事板的不同方式,那就更好了.

Also, it seems that one way (the only way?) is to use something called a storyboard. However, in VS when clicking on a storyboard in solution explorer it starts "connecting to mac" (which it's already connected to) and there's a progress bar that just goes on and on. It never loads. So if there's a different way without a storyboard, that would be better.

推荐答案

但是我如何创建另一个页面并告诉应用程序导航到它?我要创建另一个 UIViewController 吗?如果是这样,我如何告诉一个导航到另一个?

But how do I create another page and tell the app to navigate to it? Do I create another UIViewController? And if so, how do I tell one to navigate to another?

您可以按如下方式创建它:

You can create it as follow :

右键 点击 Xamarin IOS 项目 - > 添加 - > 新项目 - > 用户界面(UIViewController类/带有StoryBorad的ViewController)

Right click Xamarin IOS Project - > Add - > New Item - > User Interface (UIViewController Class / ViewController With StoryBorad )

我找到的都是使用其他 IDE 的教程.我如何在 Visual Studio 中而不是for Mac"中执行此操作?

All I've found are tutorials that use other IDEs. How do I do it in Visual Studio not "for Mac"?

这里是关于Windows 上的演练 但是关于使用故事板.下面有一个示例项目.

Here is the official document about Walkthrough on Windows however about using storyboard .And there is a sample project below it.

所以如果有没有故事板的不同方式,那就更好了.

So if there's a different way without a storyboard, that would be better.

如果 StoryBoard 中不存在 ViewController,那么您可以在没有 StoryBoard 的情况下导航到此控制器.

If ViewController not exist in StoryBoard, then you can navigate to this Controller without StoryBoard .

this.PresentViewController(new UIViewControllerSecond(), true, null);

否则如果 StoryBoard 包含其他 ViewControllers ,您也可以使用 C# 导航到下一个视图.

Else if StoryBoard contain the other ViewControllers , you also can use C# to navigate to next View.

SecondController secondController = this.Storyboard.InstantiateViewController("SecondController ") as SecondController ;
if (secondController != null)
{
    this.PushViewController(secondController , true);
}  

顺便说一下,如果将根视图控制器设置为 NavigationController ,则使用 this.NavigationController.PushViewController(...) 进行导航.

By the way , if Setting Root View Controller as NavigationController , use this.NavigationController.PushViewController(...) to navigate.

这篇关于如何在 Xamarin.iOS 应用中创建导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆