2012-09-27 74 views
0

我的故事板中有2個UIViewController,第一個(本地視圖控制器)顯示在我的ipad窗口中。還有的第二個也是在故事板(外部視圖 - 控制器)從故事板UIViewController加載視圖到外部顯示屏

我想發送的觀及其對我創建發送到外部顯示的另一個窗口的第二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

這並不是一個的viewController的視圖層次結構添加到一個窗口的正確方法。

在的iOS 4以上,你應該將其設置爲rootViewController

externalWindow.rootViewController = externalViewController; 

這可能也是值得注意的是,你實際上並沒有從情節串連圖板加載的viewController。

+0

感謝您的反饋,但那不是解決方案。我用'[whiteField addSubview:externalView.view];'但在此之前我已經叫'UIStoryboard * storyboard = self.storyboard; svc = [storyboard instantiateViewControllerWithIdentifier:@「myExternalUIViewControllerID」];' –

+0

這就是我回答的最後一行所指的。而且它仍然表明,這不是將viewController的層次結構添加到窗口的正確方法 –

相關問題