簡體   English   中英

如何在 Xamarin.iOS 應用程序中創建導航?

[英]How to create navigation in a Xamarin.iOS app?

我習慣於使用Xamarin.Forms 我在 XAML 或 C# 中創建一個頁面並導航到它。 但現在這是我第一次嘗試創建不是Xamarin.Forms的 iOS 應用程序。 我是在 Windows PC(當然,連接到 Mac)上的 Visual Studio 中進行的。 我發現ViewController類似於Xamarin.Forms Page 但是我如何創建另一個頁面並告訴應用程序導航到它? 我要創建另一個UIViewController嗎? 如果是這樣,我如何告訴一個導航到另一個?

我發現的只是使用其他 IDE 的教程。 我如何在 Visual Studio 中做到這一點而不是“for Mac”?

此外,似乎一種方法(唯一的方法?)是使用稱為 storyboard 的東西。 但是,在 VS 中,當在解決方案資源管理器中單擊 storyboard 時,它會開始“連接到 mac”(它已經連接到該 Mac),並且有一個不斷出現的進度條。 它永遠不會加載。 因此,如果沒有 storyboard 有不同的方法,那就更好了。

但是我如何創建另一個頁面並告訴應用程序導航到它? 我要創建另一個 UIViewController 嗎? 如果是這樣,我如何告訴一個導航到另一個?

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

右鍵單擊 Xamarin IOS 項目->添加->新項目->用戶界面(UIViewController Class / ViewController With StoryBorad )

在此處輸入圖像描述

我發現的只是使用其他 IDE 的教程。 我如何在 Visual Studio 中做到這一點而不是“for Mac”?

這是關於 Windows 的演練的官方文檔,但是關於使用 storyboard 的文檔。下面有一個示例項目。

因此,如果沒有 storyboard 有不同的方法,那就更好了。

如果 StoryBoard 中不存在 ViewController,那么您可以在沒有 StoryBoard 的情況下導航到此 Controller。

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

否則,如果 StoryBoard 包含其他視圖控制器,您也可以使用 C# 導航到下一個視圖。

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

順便說一句,如果將根視圖 Controller 設置為NavigationController ,請使用this.NavigationController.PushViewController(...)進行導航。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM