문제
루트 뷰 컨트롤러에서 현재 하위 뷰 (Atindex : 0)를 제거하고 그 자리에 새보기를 삽입하고 싶습니다.
현재 removeFromsUperView를 사용하여보기를 언로드하는 코드 스 니펫 만 찾을 수 있습니다.이 뷰 콘트롤러보기가 현재로드 된 것을 알아야합니다.
유일하게 주목해야 할 유일한 것은 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];
해결책
여기에 방법이 있습니다 (나는 그것을 알아 냈습니다, 예, 저입니다!)
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];
제휴하지 않습니다 StackOverflow