English 中文(简体)
Handling an external screen on the iPad
原标题:

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 dismiss 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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签