从另一种方法将子视图添加到子视图
让我首先描述一下我的情况。我有一个主视图,我希望在其中放置一个较小的滚动视图子视图。然后在代码中(在另一种方法中),我喜欢向该滚动视图子视图添加一些子视图(图像和文本视图)。甚至可能稍后删除图像和文本子视图(用另一种方法)。因此,图像和文本子视图最终成为主视图子视图的子视图。
如果这一切都发生在同一个方法中,那么这很容易完成。但我似乎无法通过另一种方法将第三代子视图添加到第二个子视图。期望类似:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否理解^^
但是如果您的问题是访问没有指针的子视图,也许您可以为子视图设置一个标签
然后在代码中您可以使用以下命令搜索此视图:
不要忘记,使用 viewWithTag 您将获得一个 UIView 类。因此,如果您需要获得特定的课程,您应该像“
祝你好运”一样施放它!
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
Then later in your code you could search for this view with :
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
Good Luck !