从另一种方法将子视图添加到子视图

发布于 2024-09-24 13:00:51 字数 352 浏览 5 评论 0原文

让我首先描述一下我的情况。我有一个主视图,我希望在其中放置一个较小的滚动视图子视图。然后在代码中(在另一种方法中),我喜欢向该滚动视图子视图添加一些子视图(图像和文本视图)。甚至可能稍后删除图像和文本子视图(用另一种方法)。因此,图像和文本子视图最终成为主视图子视图的子视图。

如果这一切都发生在同一个方法中,那么这很容易完成。但我似乎无法通过另一种方法将第三代子视图添加到第二个子视图。期望类似:

[self.view.scrollviewSubview addSubview:anotherSubview];

如何定位在主视图中作为子视图放置的滚动视图子视图。希望我的问题有意义,这真的很难用文字描述。

Let me start off by describing my situation. I have a main view that I wish to place a smaller scrollview subview in. Then later in code (in another method), I like to add some subviews (images and textviews) to that scrollview subview. And maybe even remove the image- and text-subviews later (in yet another method). So the image- and text-subviews ends up been a subview of a subview of the main view.

This is easily done, if it all happens inside the same method. But I can't seem to add a 3rd generation subview to the second subview from another method. Would expect something like:

[self.view.scrollviewSubview addSubview:anotherSubview];

How to target the scrollview-subview placed as subview in main view. Hope my question makes sense, it's really hard to describe in text.

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

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

发布评论

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

评论(1

爱殇璃 2024-10-01 13:00:51

我不确定是否理解^^

但是如果您的问题是访问没有指针的子视图,也许您可​​以为子视图设置一个标签

[ view setTag:9000 ];

然后在代码中您可以使用以下命令搜索此视图:

[ view viewWithTag:9000 ]

不要忘记,使用 viewWithTag 您将获得一个 UIView 类。因此,如果您需要获得特定的课程,您应该像“

(MyViewSubclassed*)[ view viewWithTag:9000 ]

祝你好运”一样施放它!

I'm not sure to have understood ^^

But if your problem is to access a subview you don't have a pointer to, maybe you could set a tag to your subview

[ view setTag:9000 ];

Then later in your code you could search for this view with :

[ view viewWithTag:9000 ]

Don't forget that with viewWithTag you will get an UIView class. So if you need to get a specific class, you should cast it like

(MyViewSubclassed*)[ view viewWithTag:9000 ]

Good Luck !

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