[英]Removing a superview from a method call inside that class
我正在尝试在两个视图之间切换。 问题是如何调用它。
这是解释我的情况的最简单方法:
我有家长意见。 对于子类ChildView,该子类包含一个表。 在该表中选择一个对象后,我希望切换到该父视图的另一个子视图。
父母--------- |孩子1 |孩子2
子级1是父级的子类,允许我访问父级中在子级视图1和2之间切换的方法,但是由于某些原因,当从子级1访问它时,它将无法工作。
有关如何执行此操作的任何线索? 这是基本代码:
子1- (void)changeViews
[super methodToSwitchChildViews];
父级 -(void)methodToSwitchViews
[self.child1.view removeFromSuperView];
[self.view insertSubView:child2.view atindex:0];
Super是继承中(子)类之前的类。 在这里,孩子似乎是超级视图(父视图)上的视图。 因此,请使用超级视图,而不是超级视图。
好吧,我仔细研究了一下,终于找到了解决方案。 如果有人遇到相同的问题,请执行以下操作:
在子视图的.h文件中
@class parentViewName
然后在.m文件中添加
#import "parentViewName.h"
...
- (void) functionToRemoveSelfFromView {
parentViewName *PARENT = [[parentViewName alloc] init];
// You must have a method in the parent view to toggle or remove the subview, the way
// you want it done, then call it with the new delegate. Make sure it doesn't set this
// view to nil or releases it because this method has yet to return. If animating do not
// hide this view either.
[PARENT methodToRemoveSelfFromView];
[PARENT release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.