简单的问题...

当我单击overlayController View 上的按钮时,为什么此release会使我的应用程序崩溃?

    OverlayViewController* overlayController = [[OverlayViewController alloc]
                                                initWithNibName:@"Overlay"
                                                         bundle:nil];
    self.picker.cameraOverlayView = overlayController.view;
    [overlayController release];

换句话说,如何在此viewDidLoad方法之外调用OverlayViewController方法?

奇怪...我不明白为什么我的应用程序可以工作:-)

最佳答案

好吧,我可以很容易地回答第二个问题:



只需将一个属性添加到您的viewController中:


@interface MyViewController : UIViewController {
    OverlayViewController* overlayController;
}
@property (nonatomic, retain) OverlayViewController* overlayController;
@end


@implementation MyViewController
@synthesize overlayController;

- (void)viewDidLoad {
    OverlayViewController* ovc = [[OverlayViewController alloc]
                                   initWithNibName:@"Overlay" bundle:nil];
    self.overlayController = ovc;
    [ovc release];
    self.picker.cameraOverlayView = self.overlayController.view;
}

- (void)someOtherMethod {
    [self.overlayController someMethod];
}

- (void)dealloc {
    [overlayController release];
    [super dealloc];
}

@end

10-08 05:22