midi
midi

Reputation: 4058

Xamarin get current Page from Ios section like "((AndroidAppFeatures)App.AppFeatures).Activity" in the Android Section

In the Android section of Xamarin Projekt there is "((AndroidAppFeatures)App.AppFeatures).Activity" to get the current Page.

Is there something similar for Ios to get the current viewController?

Thanks ;)

Upvotes: 0

Views: 935

Answers (1)

angak
angak

Reputation: 406

Quotes from Adam Kemp on https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service

There is no single "current" view controller in iOS. There could be multiple view controllers on the screen at once (either nested or presented as popovers or modals). I think the closest equivalent to what you're asking for would be to start with the key window's root view controller and then find the "most-presented" (for lack of a better term) view controller

And his code example:

var window= UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while (vc.PresentedViewController != null)
{
    vc = vc.PresentedViewController;
}

This should help you get there

Upvotes: 1

Related Questions