Ok, I think its possible I've misunderstood the correct way to implement an external screen on the iPad and it is causing me a lot of headaches. Since this is a long post, what I'm trying to do is create and send a view to an external screen over VGA, and remove the screen once I'm done with it. I'm having retain count issues so can't get it to work.
I have a view controller that can be called up onto the iPad at any time. When this view loads (it is a remote, similar to Keynote presentation) I check for an external screen, then create a window and add a view to the extra monitor.
in my ipadViewController.h
<-- the view that stays on the iPad
I have
@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
(There is more, but that is the external screen stuff).
in ipadViewController.m
:
@synthesize externalScreen;
@synthesize externalWindow;
@synthesize presentationView;
So I try to do a few things when the view loads:
Get the external screen (if possible)
Create apresentationViewController
and add it to the extra screen
- (void)viewDidLoad {
[super viewDidLoad];
[self getExternalScreen];
[self createPresentationAndSendToWindow];
}
to get the screen I do the following getExternalScreen:
:
if ([[UIScreen screens] count] > 1)
{
for (UIScreen *currentScreen in [UIScreen screens])
{
if (currentScreen != [UIScreen mainScreen])
self.externalScreen = [currentScreen autorelease];
}
}
and to send the view to it 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];
}
in dealloc
I try to cleanup with:
[presentationView release];
[externalScreen release];
//[externalWindow release]; <- that would crash
Problem I have is that when I dismi开发者_高级运维ss the remoteViewController
(it is modal), after releasing externalScreen
has a retain count = 1 and externalWindow has retain count = 2.
The crash caused by externalWindow release
disappears if I don't release presentationView
(but then I'm leaking presentationView
.
Your problem is here:
for (UIScreen *currentScreen in [UIScreen screens])
{
if (currentScreen != [UIScreen mainScreen])
self.externalScreen = [currentScreen autorelease];
}
Remove the autorelease
. You shouldn't be releasing something you didn't create or retain.
you are autoreleasing externalView on
self.externalWindow = [[[UIWindow alloc] initWithFrame:externalBounds] autorelease];
and then you assign an autorelease view to it
self.externalScreen = [currentScreen autorelease];
you cannot release an autoreleased view, or it will crash.
精彩评论