Changing ViewController from code position Xamarin.iOS

MondonnoMondonno Member ✭✭
edited August 12 in Xamarin.iOS

I have a problem because I don't know how to change the ViewController display in the code, otherwise I would like to change the ViewController display using the code,
Thank you for every little tip !!!

Best Answer

  • MondonnoMondonno ✭✭
    edited August 15 Accepted Answer

    I'm sorry I took time, thank you @ColeX
    @JohnHardman, the solution to this problem was simple, you had to give ViewController "Storyboard ID" in Properties, and to switch ViewController such code:

    ExampleViewController tabviewController = Storyboard.InstantiateViewController("ExampleID") as ExampleViewController;
    this.NavigationController.PushViewController(ExampleViewController, true);
    

    ExampleViewController is an example ViewController, "Example ID" is an example "Storyboard ID", to change the displayed ViewController, and for this code to work (above) you need to connect the NavigationController with the current ViewController (currently displayed ViewController) and that's all !!!

    Thank you all for your help, I consider the topic finished :wink:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Give the control a name on storyboard, then you could relate it in your code .

    Refer https://docs.microsoft.com/en-us/xamarin/ios/user-interface/designer/introduction?tabs=windows

  • MondonnoMondonno Member ✭✭
    edited August 12

    How to do it?

  • ColeXColeX Member, Xamarin Team Xamurai

    See the image

  • MondonnoMondonno Member ✭✭

    Could you show step by step how to do it and show the code? :'(

  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 13

    What have you tried and what exact problem did you meet?

    I think the step is clear in the documentation i provided .

    1. Drag a new control on storyboard , give it a name ,for example we call it A .

    2. Change the control's appearance in code behind.(place the code in corresponding ViewController class)

  • MondonnoMondonno Member ✭✭

    But I mean change the displayed ViewController. Could you tell me how to change the ViewController display from the code position? Is there any code for this?

  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 13

    Sorry , i don't get you . Do you want to change the ViewController display from another ViewController code hehind?

  • MondonnoMondonno Member ✭✭
    edited August 13

    @ColeX said:
    Sorry , i don't get you . Do you want to change the ViewController display from another ViewController code hehind?

    No, I just want to change the displayed ViewController from the code position. And I don't know how to do it, that's why I am asking for help

  • ColeXColeX Member, Xamarin Team Xamurai

    @JohnHardman @NMackay I'm still confused, do you have any idea?

  • JohnHardmanJohnHardman GBUniversity mod

    @ColeX said:
    @JohnHardman @NMackay I'm still confused, do you have any idea?

    No. I'm not clear as to what the OP is after.

  • MondonnoMondonno Member ✭✭
    edited August 14

    I would like to change the display ViewController from the code position, that's all I want !!! :(

  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 14

    display ViewController from the code position

    Could you give a more detailed description about this ?

    Any screen shot would be helpful .

  • MondonnoMondonno Member ✭✭

    I would like to change the viewcontroller displayed from the code position. I would like to know the method that will change the displayed viewcontroller, e.g. I have viewcontroller1 and viewcontroller2 and now let's assume that in the first viewcontroller (viewcontroller1) I have a textfield and a button and if the textfield has the text "Hello" then after pressing the button it will go to the second viewcontroller ( viewcontroller2) and if the value of the text in the text field is different from "Hello" after clicking the button, it does not go to viewcontroller2. And I would like you to help me solve this problem. :/

  • MondonnoMondonno Member ✭✭
    edited August 15 Accepted Answer

    I'm sorry I took time, thank you @ColeX
    @JohnHardman, the solution to this problem was simple, you had to give ViewController "Storyboard ID" in Properties, and to switch ViewController such code:

    ExampleViewController tabviewController = Storyboard.InstantiateViewController("ExampleID") as ExampleViewController;
    this.NavigationController.PushViewController(ExampleViewController, true);
    

    ExampleViewController is an example ViewController, "Example ID" is an example "Storyboard ID", to change the displayed ViewController, and for this code to work (above) you need to connect the NavigationController with the current ViewController (currently displayed ViewController) and that's all !!!

    Thank you all for your help, I consider the topic finished :wink:

  • ColeXColeX Member, Xamarin Team Xamurai

    Glad you've resolved it , could you accept your own solution to finish the thread?

Sign In or Register to comment.