gpt4 book ai didi

iPhone - 使用类属性时释放崩溃

转载 作者:行者123 更新时间:2023-12-03 20:46:52 24 4
gpt4 key购买 nike

简单的问题...

当我点击overlayController View 上的按钮时,为什么这个版本会使我的应用程序崩溃?

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

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

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

最佳答案

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

How can the OverlayViewController methods be called outside of this viewDidLoad method?

只需向您的 viewController 添加一个属性即可:

MyViewController.h:

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

MyViewController.m:

@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

关于iPhone - 使用类属性时释放崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5318267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com