2009-03-01 9 views
1

ルートビューコントローラから現在のサブビュー(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]; 

答えて

1

はそれを行う方法である

おかげで、十分ではない(私はYEYくれ、それを考え出した!)

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]; 
関連する問題