iPhone:“发送到实例的选择器无法识别”错误

发布于 2024-09-04 03:25:46 字数 315 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-09-11 03:25:46

当在 TestViewController displayModal: 中显示 ModalViewController 时,您释放了 modalController(第 20 行)。不要这样做 - 您需要 ViewController 才能保持活动状态。如果释放它,则只有视图保持活动状态(因为当添加为子视图时它会被保留)。

另外,在 ModalViewController hideModalEnded 中,您释放了没有保留的 modalView,因此我也会删除该视图。

所以现在你需要在视图被删除后释放 ModalViewController 的实例。你可以通过[自我释放]来做到这一点;在 hideModalEnded 中,但这似乎是一个不寻常的模式,我感觉这样做不太好。

一些建议:

  • 将显示和隐藏方法保留在
    同一个班级。
  • 随身携带一个 ivar
    控制器。
  • 另一种可能性:删除
    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:

  • Keep the show and hide methods in the
    same class.
  • Keep an ivar around with the
    controller.
  • Another possiblity: Remove the
    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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文