从该类内部的方法调用中删除超级视图
我现在正在尝试在两种视图之间切换。问题是如何调用它。
这是解释我的情况的最简单方法:
我有一个家长视图。 有一个子类 ChildView,其中包含一个表。 在该表中选择一个对象后,我希望切换到该父视图的不同子视图。
家长--------- |Child 1 |Child 2
Child 1 是 Parent 的子类,允许我访问 Parent 中在 Child Views 1 和 2 之间切换的方法,但由于某种原因,从 Child 1 访问它时它不起作用。
有关如何的任何线索做这个吗?基本代码如下:
Child 1 - (void)changeViews
[super methodToSwitchChildViews];
父级 - (void)方法切换视图
[self.child1.view removeFromSuperView];
[self.view insertSubView:child2.view atindex:0];
I'm trying to switch between two views right now. The problem is how it is called.
Heres the easiest way to explain my situation:
I have a Parent View.
With a subclass ChildView, that contains a table.
Upon selecting an object in that table, I wish to switch to a different child view of that parent view.
Parent---------
|Child 1 |Child 2
Child 1 is a subclass of Parent to allow me to access a method in Parent that switches between Child Views 1 and 2, but for some reason it wont work when accessing it from Child 1.
Any clues on how to do this? Heres the basic code:
Child 1
- (void) changeViews
[super methodToSwitchChildViews];
Parent
- (void) methodToSwitchViews
[self.child1.view removeFromSuperView];
[self.view insertSubView:child2.view atindex:0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Super 是继承中位于(子)类之前的类。在这里,孩子们似乎是超级视图(父母)的视图。所以使用superview,而不是super。
Super is the class that precedes a (sub)class in inheritance. Here the children seem to be views on a superview (parent). So use superview, and not super.
好吧,我查了很多资料,终于找到了解决方案。如果有人遇到同样的问题,您可以这样做:
在子视图的 .h 文件中执行
然后在 .m 文件中添加
Okay, I dug around quite a bit and finally figured out a solution. In case anybody ever has the same problem here's what you do:
In the .h file of the child view do
Then in the .m file add