Forum Xamarin Xamarin.iOS

Problem with initialize a viewController

TripleDoubleTripleDouble BGMember ✭✭✭

I have a ModalViewController class. There are some properties and an event

When a make an instance like this

var detailViewController = mStoryBoard.InstantiateViewController("DetailView");
detailViewController.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
mViewController.PresentViewController(detailViewController, true, null);

I can not access these properties and event

When I make an instance like this

var detailViewController = new ModalViewController();

There is not this problem , but the screen of viewController is emty / black - The views / controls are not visible

I need to access the properties and event from ModalViewController class


  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    Have you tried:

    var detailViewController = mStoryBoard.InstantiateViewController("DetailView") as ModalViewController;


    The above will cast the view controller with storyboard ID of "DetailView" to a ModalViewController... assuming that your DetailView is indeed a ModalViewController. The InstantiateViewController method always returns type UIViewController, so you always have to cast it to the exact subclass of UIViewController that you are using if you want access to the methods and properties of your UIViewController sub-class.

Sign In or Register to comment.