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

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

问题描述

我曾经使用过 Xamarin.Forms .我在XAML或C#中创建一个Page并导航到它.但是,现在这是我第一次尝试创建不是 Xamarin.Forms 的iOS应用.我正在从Windows PC(当然,连接到Mac)上的Visual Studio进行操作.我发现 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中而不是对于Mac"中做到这一点?

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

此外,似乎一种方法(唯一的方法是)使用一种称为情节提要的东西.但是,在VS中,当在解决方案资源管理器中单击情节提要时,它会开始连接到Mac"(已连接到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?

您可以如下创建它:

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

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

我发现的所有都是使用其他IDE的教程.如何在Visual Studio中而不是对于Mac"中做到这一点?

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

这是有关

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.

如果StoryStorard中不存在ViewController,则可以在没有StoryBoard的情况下导航到该Controller.

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

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

否则,如果StoryBoard包含其他ViewController,则还可以使用C#导航到下一个View.

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天全站免登陆