我想从我的根视图控制器中删除当前子视图(添加atIndex:0)并在其位置插入一个新视图。
目前我只能找到显示使用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];
答案 0 :(得分: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];