删除视图并加载另一个视图

时间:2015-08-28 12:24:48

标签: ios objective-c uiview

我想在点击按钮后删除视图并加载另一个视图我试图解释你的代码在下面

[self removeFromSuperview];
FZforgetpassword *forget=[[[NSBundle mainBundle]loadNibNamed:@"FZforgetpassword" owner:self options:nil] objectAtIndex:0];
forget.delegate=self;
forget.frame=self.bounds;
[forget showCustomView:4];
[self addSubview:forget];

第一行我删除视图然后加载另一个视图,但是当我运行此代码时我没有得到第二个视图

2 个答案:

答案 0 :(得分:0)

试试这个。

//add subview first
FZforgetpassword *forget=[[[NSBundle mainBundle]loadNibNamed:@"FZforgetpassword" owner:self options:nil] objectAtIndex:0];
forget.delegate=self;
forget.frame=self.bounds;
[forget showCustomView:4];
[self addSubview:forget];
//finally remove 'self view'
[self removeFromSuperview];

注意:如果你删除“自我”'首先是[自我添加子视图:忘记];'无法执行。因为现在' self = nil'

答案 1 :(得分:0)

这从superview中移除self,如果你没有任何引用,它将被取消分配:

[self removeFromSuperview];
相关问题