gpt4 book ai didi

ios - '[[myView viewWithTag :tag] removeFromSuperview]' Removes all my UIButtons

转载 作者:行者123 更新时间:2023-11-29 04:23:03 25 4
gpt4 key购买 nike

出于某种原因,我似乎无法在不删除所有 UIButton 的情况下删除 UIImageView。所有 subview 都添加到我的主视图 _ourView 中,并且 UIButtons 没有被赋予标签(默认 0),而我的图像被赋予 tag=5。

当我打电话时

NSInteger o = [obj intValue]; //This is the letter "O" not 0, and o = 5 in this case (which is what my subview tag is)
UIView *hangmanView = [_ourView viewWithTag:o];
[hangmanView removeFromSuperview];
[_ourView setNeedsDisplay];

我的所有按钮也消失了。

有什么指点吗?

编辑:如果您想查看更多代码,我已将我的项目上传到 github。以下是该文件的链接:https://github.com/elayman/Hangman/blob/master/Hangman/HangmanViewController.m#L172

最佳答案

您已将按钮添加到 ImageView 中,或者与该标记匹配的 View 是按钮的 super View 。

在调试器中检查标记值是什么(可能不是您想象的那样)以及 viewWithTag 返回的 View 是什么。

标签在大多数情况下无论如何都是无用的。为什么不使用 socket 或 socket 集合,它更加明确和可读。

关于ios - '[[myView viewWithTag :tag] removeFromSuperview]' Removes all my UIButtons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12721388/

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