2010-07-13 85 views
3

好吧,我認爲它可能是我誤解了在iPad上實現外部屏幕的正確方法,它給我帶來了很多令人頭疼的問題。 由於這是一篇很長的文章,我想要做的是創建並通過VGA將視圖發送到外部屏幕,並在完成後刪除屏幕。我保留計數問題,所以無法使其工作。在iPad上處理外部屏幕

我有一個視圖控制器,可以在任何時候調用到iPad上。當這個視圖加載時(它是一個遙控器,類似於Keynote演示文稿),我檢查一個外部屏幕,然後創建一個窗口並添加一個視圖到額外的監視器。

在我ipadViewController.h < - 即停留在iPad上

認爲我有

@interface ipadViewController : UIViewController { 

PresentationViewController *presentationView; 
UIScreen *externalScreen; 
UIWindow *externalWindow; 
} 

@property (nonatomic, retain) UIScreen *externalScreen; 
@property (nonatomic, retain) UIWindow *externalWindow; 
@property (nonatomic, retain) PresentationViewController *presentationView; 
@end 

(還有更多,但那是外屏的東西)。

ipadViewController.m

@synthesize externalScreen; 
@synthesize externalWindow; 
@synthesize presentationView; 

所以我試着做了幾件事情,當視圖加載:

獲取外部屏幕(如果可能) 創建一個presentationViewController並將其添加到額外的屏幕

- (void)viewDidLoad { 
[super viewDidLoad]; 

[self getExternalScreen]; 
[self createPresentationAndSendToWindow]; 
} 

讓屏幕我下面getExternalScreen:

if ([[UIScreen screens] count] > 1) 
{ 
    for (UIScreen *currentScreen in [UIScreen screens]) 
    { 
     if (currentScreen != [UIScreen mainScreen]) 
      self.externalScreen = [currentScreen autorelease]; 
    } 

} 

和視圖發送給它createPresentationAndSendToWindow:

if (self.presentationPath == nil) return; 
PresentationViewController *viewController = [[PresentationViewController alloc] initWithNibName:@"CanvasPresentation" bundle:nil]; 


self.presentationView = viewController; 
[viewController release]; 

if (self.externalWindow == nil) 
{ 
    CGRect externalBounds = [self.externalScreen bounds]; 
    self.externalWindow = [[[UIWindow alloc] initWithFrame:externalBounds] autorelease]; 

    [self.externalWindow addSubview:self.presentationView.view]; 

    self.externalWindow.screen = self.externalScreen; 

    [self.externalWindow makeKeyAndVisible]; 
} 

dealloc我試圖清理與:

[presentationView release]; 
[externalScreen release]; 
//[externalWindow release]; <- that would crash 

問題我已經是,當我駁回remoteViewController (它是模態的),釋放後externalScreen的保留計數= 1,externalWindow保留計數= 2。

externalWindow release引起的崩潰消失,如果我不釋放presentationView(但後來我泄漏presentationView

回答

1

你的問題是在這裏:

for (UIScreen *currentScreen in [UIScreen screens]) 
{ 
    if (currentScreen != [UIScreen mainScreen]) 
     self.externalScreen = [currentScreen autorelease]; 
} 

取出autorelease。你不應該發佈你沒有創建或保留的東西。

0

你在

self.externalWindow = [[[UIWindow alloc] initWithFrame:externalBounds] autorelease]; 

自動釋放externalView然後分配一個自動釋放,以便它

self.externalScreen = [currentScreen autorelease]; 

您無法釋放的自動釋放的看法,否則就會崩潰。