【问题标题】:remove the view and load another view删除视图并加载另一个视图
【发布时间】:2015-11-23 02:45:17
【问题描述】:

我想在单击按钮后删除视图并加载另一个视图,我试图向您解释的代码如下

[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];

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

【问题讨论】:

  • 你在使用自动布局吗?

标签: ios objective-c uiview


【解决方案1】:

试试这个。

//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' 然后 '[self addSubview:forget];'无法执行。因为现在'self = nil'

【讨论】:

    【解决方案2】:

    这会从superview中删除self,如果你没有任何引用它会被释放:

    [self removeFromSuperview];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 2011-10-26
      • 1970-01-01
      相关资源
      最近更新 更多