iPhone:“发送到实例的选择器无法识别”错误
我正在尝试使用 ramin.firoozye.com 上的“iPhone 上的半模态(透明)对话框”中的代码在我的应用程序中实现部分覆盖模式。覆盖功能有效,它将模式滑入视图中,但从模式控制器调用任何 IBAction 会导致“无法识别的选择器发送到实例”崩溃。
我用隔离的代码重新创建了基本功能,它触发了相同的错误。要了解我在说什么,您可以在此处下载测试项目 。
我确信我只是在这里错过了一些简单的东西。任何帮助将不胜感激。
I’m trying to implement a partial overlay modal in my app with the code from “Semi-Modal (Transparent) Dialogs on the iPhone” at ramin.firoozye.com. The overlay functionality works and it slides the modal into view, but calling any IBAction from the modal's controller causes an “Unrecognized Selector Sent to Instance” crash.
I recreated the basic functionality with that code isolated, and it triggers the same error. To see what I’m talking about, you can download the test project here.
I’m sure I’m just missing something simple here. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当在 TestViewController displayModal: 中显示 ModalViewController 时,您释放了 modalController(第 20 行)。不要这样做 - 您需要 ViewController 才能保持活动状态。如果释放它,则只有视图保持活动状态(因为当添加为子视图时它会被保留)。
另外,在 ModalViewController hideModalEnded 中,您释放了没有保留的 modalView,因此我也会删除该视图。
所以现在你需要在视图被删除后释放 ModalViewController 的实例。你可以通过[自我释放]来做到这一点;在 hideModalEnded 中,但这似乎是一个不寻常的模式,我感觉这样做不太好。
一些建议:
同一个班级。
控制器。
ModalViewController 完全和
将所有内容都放在 TestViewController 中 - 但这很大程度上取决于实际情况中将发生多少操作。
When showing your ModalViewController in TestViewController displayModal:, you release your modalController (line 20). Don't do this - you need the ViewController to stay alive. If you release it, only the view keeps alive (as it is retained when added as a subview).
Also, in ModalViewController hideModalEnded you release modalView, which you didn't retain, so I'd remove that one as well.
So now you need to release just the instance of ModalViewController after the view got removed. You can do this by [self release]; in hideModalEnded, but this seems to be an unusual pattern and I don't feel good doing it.
Some suggestions:
same class.
controller.
ModalViewController altogether and
put everything in TestViewController - But this very much depends on how much action there will be going on in the real thing.