我的故事板中有2个UIViewController,第一个(本地视图控制器)显示在我的ipad窗口中。故事板(外部视图控制器)还有第二个
我想将第二个UIViewController(外部视图控制器)的视图及其内容发送到我创建的另一个窗口,以发送到外部显示器。
我可以创建UIwindow并将其发送到外部显示器(UIScreen = 1),我可以添加一个视图,然后添加标签之类的东西就好了。 (他们在第二次展示时显示)
但是如果我想将UIviewcontroller“View”(包含其所有内容)发送到我为外部显示器创建的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;
}
答案 0 :(得分:0)
这不是将viewController的视图层次结构添加到窗口的正确方法。
在iOS 4及更高版本中,您应将其设置为rootViewController
externalWindow.rootViewController = externalViewController;
也可能值得注意的是,您实际上并未从故事板加载viewController。