iPhone - 使用类属性时释放崩溃
简单的问题...
为什么当我单击overlayController 视图上的按钮时,这个release
会使我的应用程序崩溃?
OverlayViewController* overlayController = [[OverlayViewController alloc]
initWithNibName:@"Overlay"
bundle:nil];
self.picker.cameraOverlayView = overlayController.view;
[overlayController release];
换句话说,如何在 viewDidLoad 方法之外调用 OverlayViewController 方法?
奇怪...我不明白为什么我的应用程序可以工作:-)
Simple question...
Why does this release
crash my app when I click on a button that is on the overlayController view?
OverlayViewController* overlayController = [[OverlayViewController alloc]
initWithNibName:@"Overlay"
bundle:nil];
self.picker.cameraOverlayView = overlayController.view;
[overlayController release];
Said another way, how can the OverlayViewController methods be called outside of this viewDidLoad method?
Strange... I do not understand why my app is working :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我可以很容易地回答第二个问题:
只需将一个属性添加到您的 viewController 中:
Well, I can answer the second question easily enough:
Simply add a property to your viewController:
是的,但它不保留
overlayController
,它会在[overlayController release]
后愉快地释放。为了能够调用overlayController方法,请将其保存在实例变量中。无论如何你都必须这样做以避免崩溃和/或泄漏。
Yes but it doesn't retain
overlayController
which will be happily deallocated after[overlayController release]
.To be able to call
overlayController
methods keep it in instance variable. You have to do this anyway to avoid crashes and/or leaks.您将overlayController 的视图分配给您的属性,但随后释放整个控制器。 时,setter 才会保留。
仅当您指定了此设置(如查看cameraOverlayView 的属性,如果这确实保留了视图)
You're assigning the view of the overlayController to your property but release the whole controller afterwards. The setter does only retain if you've specified this like
Have a look at the property of cameraOverlayView if this really retains the view.