简体   繁体   中英

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

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 写下以下两行
Previous view will be removed and new view ie will be added. 将被添加。

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

Cheers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM