[英]Load view from storyboard UIViewController to external display
我的故事板上有2个UIViewController,第一个(本地视图控制器)显示在我的ipad窗口中。 情节提要中还有第二个(外部视图控制器)
我想将第二个UIViewController(外部视图控制器)的视图及其内容发送到我创建的另一个窗口中,以发送到外部显示器。
我可以创建一个UIwindow并将其发送到外部显示器(UIScreen = 1),然后可以向其添加视图,然后向其添加标签之类的东西。 (它们显示在第二个显示屏上)
但是,如果我要将UIviewcontroller“视图”(及其所有内容)发送到为外部显示器创建的Windows,则看不到它。
我可以这样做吗?
看下面的代码:
//this code is at my main view controller
#import "ASHExternalViewController.h" //for External View Controller
if ([[UIScreen screens] count] > 1)
{
// Associate the window with the second screen.
// The main screen is always at index 0.
UIScreen* secondScreen = [[UIScreen screens] objectAtIndex:1];
CGRect screenBounds = secondScreen.bounds;
//Alloc external window
UIWindow *externalWindow = [[UIWindow alloc] initWithFrame:screenBounds];
externalWindow.screen = secondScreen;
// Add a white background View to the window
UIView* whiteField = [[UIView alloc] initWithFrame:screenBounds];
whiteField.backgroundColor = [UIColor whiteColor];
[externalWindow addSubview:whiteField];
//up to this point all OK, I can see the white background view in the external display
//
//Add uiviewcontoller at storyborad to external window
ASHExternalViewController *_externalView = [[ASHExternalViewController alloc] initWithNibName:@"ASHExternalViewController" bundle:nil];
[whiteField addSubview: externalView.view];
//does no add the view in the external UIViewController in story board
// Go ahead and show the window.
externalWindow.hidden = NO;
}
这不是将viewController的视图层次结构添加到窗口的正确方法。
在iOS 4及更高版本中,您应该将其设置为rootViewController
externalWindow.rootViewController = externalViewController;
还可能值得注意的是,您实际上并没有从情节提要中加载viewController。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.