Moving from one viewcontroller to another viewcontroller in Mac OS X using Xamarin.Mac

StackOverflow https://stackoverflow.com/questions/19680539

  •  01-07-2022
  •  | 
  •  

سؤال

I am a complete newbie in Mac development. I want to achieve the following functionality :-

I have a view with a two textfields and a login button.When the user clicks on login button another view should open.

Now my main view is in MainWindow.xib file..

I added another view using

Add-> New File-> Xamarin.Mac-> Cocoa View with controller, which generated the following files:-

1.) NewView.cs

2.) NewView.xib

3.) NewViewController.cs

After searching quite a lot on net i did not get the exact way to achieve this functionality. I referred this thread

Easy Switching of "View Controllers" in Mac Apps (similar to iOS)

but could not get the much out of it. Can someone tell me how to simply navigate from one view controller to another using Xamarin.Mac and where what code is to be written??

Any links,code snippet or sample code will be of great help!!

Thanks a ton in advance!

هل كانت مفيدة؟

المحلول

Here is the answer :-

If you want to switch from one view to another below code snippet shows how to add and remove views:-

Write the below two lines in your Action of login button.
Previous view will be removed and new view i.e SecondView will be added.

this.View.Superview.AddSubview(new SecondViewController().View);
this.View.RemoveFromSuperview(); 

Cheers!!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top