Search code examples
ipadviewxamarin.iosuitabbarcontroller

Call a ViewController with Button from a TabBarController


i want to call several Views in my Xamarin.ios App. This App hast an TabBarController, which works correctly. Now I want to call the Views, added to my TabBarController, with Buttons on the MainPage.

The way which the user should go should work like this:

  1. Clicking on a picture (Button), which shows an ActionSheet. This shows a short explanation about the side and gives two options, "Ok" and "show view".
  2. User pressed "show view" and the side will be presented. <- Here is the Problem.

I tried the following:

this.TabBarController.PresentViewController(this.TabBarController.ViewControllers[1], true, null);

and

TabBarController.SelectedIndex = 1;
PerformSegue("Einstellungen", sender: this.TabBarController);

but nothing worked. I just getting some Errors and the application crashes...

Can somebody give me a good idea?


Solution

  • To change the tabs of a UITabBarController all you have to do is change the current index.

    this.TabBarController.SelectedIndex =*TabIndex*;
    

    TabBarController is the reference of your UITabBarController object, Make sure that you are doing this over MainThread and things should work fine.

    Please check this for more details https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/creating-tabbed-applications

    Feel free to get back if you have any queries