在 Xcode 中删除类的视图
你好 有没有办法从特定类的另一个视图中删除一个视图? 我的意思是我有一个包含多个其他视图的视图,例如滚动视图、图像视图、表格视图,而我只想删除滚动视图。 我以为代码会是这样的:
for (UIView *view in self.view.superview.subviews) {
if ([view.class == [Class UIScrollView]]]) {
[view removeFromSuperview];
}
}
但这不起作用。我可以在索引处使用对象:但是因为我们不知道滚动视图有什么索引,所以它也不起作用。 (我想)
有人知道这个问题的答案吗? 非常感谢!
Hi
Is there a way to remove a view from another view of a specific class?
What I mean I have a view with multiple other views like a scrollview, imageview, tableview and I only want to remove the scrollview.
I thought the code would be something like this:
for (UIView *view in self.view.superview.subviews) {
if ([view.class == [Class UIScrollView]]]) {
[view removeFromSuperview];
}
}
But this didn't work. I could work with object at index: but because we don't know what index the scrollview has,so it also won't work. (I think)
Does someone knows the answer to this problem?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的意思是这个吗?
Is it this what you mean?
如果您可以将 IBOutlet 设置为子视图,只需调用 removeFromSuperview 在已保存的插座上。
(如果不起作用,请记录出口以确保其设置正确)
(非常确定这适用于 NSView 和 UIView)
If you can set an IBOutlet to the subview just call removeFromSuperview on the saved outlet.
(log the outlet to make sure it's set properly if that doesn't work)
(pretty sure that applies to both NSView and UIView)