问题
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?
All I've found are tutorials that use other IDEs. How do I do it in Visual Studio not "for 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.
回答1:
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 :
Right click Xamarin IOS Project - > Add - > New Item - > User Interface (UIViewController Class / ViewController With StoryBorad )
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.
If ViewController not exist in StoryBoard, then you can navigate to this Controller without StoryBoard .
this.PresentViewController(new UIViewControllerSecond(), true, null);
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);
}
By the way , if Setting Root View Controller as NavigationController
, use this.NavigationController.PushViewController(...)
to navigate.
来源:https://stackoverflow.com/questions/58087254/how-to-create-navigation-in-a-xamarin-ios-app