【问题标题】:removing some view from a view controller从视图控制器中删除一些视图
【发布时间】:2009-03-01 19:09:43
【问题描述】:

我想从我的根视图控制器中删除当前的子视图(添加 atIndex:0)并在其位置插入一个新视图。

目前我只能找到代码 sn-ps 显示使用 removeFromSuperView 卸载视图,这需要您知道当前加载的 viewcontrollers 视图。

唯一需要注意的是,我在 rootcontrollers 视图中插入了另一个子视图,我不想卸载它。所以删除所有子视图的代码是不够的

谢谢,

米

if(self.firstscr == nil)
    {
        firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
        self.firstscr = f;
        [f release];
    }

    ///This is my attempt at getting to the currently loaded view :P
  [[self.view subviews atIndex:0].view removeFromSuperView];


    [self.view insertSubview:firstscr.view atIndex:0];

【问题讨论】:

    标签: iphone cocoa-touch


    【解决方案1】:

    这是怎么做的(我想通了,是的!)

    if(self.firstscr == nil)
        {
            firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
            self.firstscr = f;
            [f release];
        }
    
        //Remove whatever view is currently loaded at index 0, this index is only to be used by "page" views
        UIView *v = [self.view.subviews objectAtIndex:0];
        [v removeFromSuperview];
    
    
        [self.view insertSubview:firstscr.view atIndex:0];
    

    【讨论】:

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