Call function from any ViewController in your app

I will like to know the best way to call a function that is accessible from everywhere in your app. For examble: GetLanguage that would return the language that the user chose at the start of the app. Should I do this from the AppDelegate? if yes, I can't I call the function from the controllers?

Help would be welcome.

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    This sounds like a basic C# question. If you need to call a method on an instance of an object then you need to have a reference to that object. There are many ways to do that, including:

    • An argument in your constructor
    • A property that some other code fills in
    • A static property somewhere else that your code can fetch

    If you need to call a static method then just call it. Either way the answer is the same for Xamarin.iOS as it is for any other C# application.

    Either you need to clarify this question and explain what the challenge is (specific to Xamarin.iOS) or you may need to just learn some C# fundamentals.

  • mrobillardmrobillard CAMember

    You are right, I will look to learn more about C# fundamentals. I wasn't sure if it was some particularities of xamarin or c#.

    Thanks

Sign In or Register to comment.