[英]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.