RemoveFromSuperview 发送无法识别的选择器到视图控制器

发布于 2024-09-16 06:39:35 字数 1107 浏览 6 评论 0原文

我有一个名为 GobanVC 的视图控制器。它添加一个子视图来实现放大效果。这工作正常,但是当我调用removeSuperview来摆脱它时,我收到无法识别的选择器错误:

2010-08-26 10:10:04.014 GoGrinder[4257:207] -[GobanVC _invalidateSubviewCache]: unrecognized selector sent to instance 0x5a2f540
2010-08-26 10:10:04.016 GoGrinder[4257:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GobanVC _invalidateSubviewCache]: unrecognized selector sent to instance 0x5a2f540'

GobanVC是UIViewController子类,而不是视图,所以我不确定为什么它会收到此消息。我添加这样的子视图:

if(magnifier == nil)
{
    magnifier = [[MagnifierView alloc] initWithFrame:gobanView.bounds];
    magnifier.viewref = gobanView;
    [gobanView addSubview:magnifier];
}

gobanView 是一个 UIView IBOutlet。

在touchesEnded中,我尝试像这样删除子视图:

if(magnifier != nil)
{
    [magnifier removeFromSuperview];
    [magnifier release];
    magnifier = nil;
}

有什么想法吗?似乎 _invalidateSubviewCache 应该发送到视图的父视图,即 UIView。我不明白为什么要打电话给 VC。

更新:

gobanVC.view 是 gobanView 的父级。我使用IB添加了一个子视图,gobanView是它连接到的IBOutlet。

I have a view controller called GobanVC. It's adding a subview to do a magnification effect. That works fine, but when I call removeSuperview to get rid of it, I get an unrecognized selector error:

2010-08-26 10:10:04.014 GoGrinder[4257:207] -[GobanVC _invalidateSubviewCache]: unrecognized selector sent to instance 0x5a2f540
2010-08-26 10:10:04.016 GoGrinder[4257:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GobanVC _invalidateSubviewCache]: unrecognized selector sent to instance 0x5a2f540'

GobanVC is a UIViewController subclass, not a view, so I'm not sure why it's receiving this message. I'm adding the subview like this:

if(magnifier == nil)
{
    magnifier = [[MagnifierView alloc] initWithFrame:gobanView.bounds];
    magnifier.viewref = gobanView;
    [gobanView addSubview:magnifier];
}

gobanView is a UIView IBOutlet.

In touchesEnded I try to remove the subview like this:

if(magnifier != nil)
{
    [magnifier removeFromSuperview];
    [magnifier release];
    magnifier = nil;
}

Any ideas? It seems like _invalidateSubviewCache should be sent to the parent of the view, which is a UIView. I don't see why the VC is getting called instead.

Update:

gobanVC.view is the parent of gobanView. I added a child view using IB, and gobanView is the IBOutlet it is connected to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼睛会笑 2024-09-23 06:39:35

很有趣。我假设 GobanVC.view == gobanView ?看起来幕后正在发生一些复杂的事情,可能需要进行一些仔细的梳理才能弄清楚 magnifier 如何获得对 GobanVC 的引用。也许 gobanView 实际上包含对 gobanVC 的引用?

我不知道您愿意在这里显示多少代码,但如果可以的话,请显示尽可能多的 .m 代码,以便我们其他人可以看一下。 UIViewController 视图加载的计时存在一些不直观的问题,因此查看所有代码会很有帮助。

Pretty interesting. I'm assuming GobanVC.view == gobanView? It seems like something convoluted is going on behind the scenes, and it'll probably take some fine combing to figure out how magnifier could possibly get a reference to GobanVC. Maybe gobanView actually contains a reference to a gobanVC?

I don't know how much code you're willing to show on here, but if you can, show as much of .m as possible so the rest of us can take a look. There are some unintuitive issues with timing in UIViewController view loading, so having all the code to look at helps a ton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文