简体   繁体   中英

View not loading from Storyboard on InstantiateViewController() call

I am trying to present a view controller in a Forms dependency service. But I keep getting a black screen. I can get it to work when I use Swift in Xcode, but not using Xamarin.

Controller outlets are not loading either. Strange thing is changes to vc.View do appear. It's as though it's creating a blank view and not actually loading from the storyboard.

My code is as follows:

var storyboard = UIStoryboard.FromName("StoryboardView", null);
var controller = storyboard.InstantiateViewController("StoryboardViewVC");

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

vc.PresentViewController(controller, true, null);

Adding a call to LoadViewIfNeeded() does not fix the issue.

I have double-checked that the storyboard and controller names match, which they do. I've searched for answers, but everything I'm finding revolves around not writing code to load the controller from the storyboard or nib.

var controller = (UIViewController)storyboard.InstantiateViewController("StoryboardViewVC");

使用您分配给视图的类,该类可能会加载视图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM