2012-12-14 32 views
-1

我目前在topViewControllerUIView被添加到我的rootViewController。有沒有什麼辦法可以通過popToRootViewContollerrootViewController之前刪除所有UIViews我如何從rootViewController刪除所有UIViews

+0

你能解釋一下「topViewConrtoller」究竟是什麼意思嗎? –

+0

您是否將新視圖添加爲子視圖? –

+0

在viewWillDisapper中執行此操作,因爲每當您再次訪問您的rootView時,都會初始化againg中的所有視圖。 – Rajneesh071

回答

0

試試這個:

-(void)viewWillAppear:(BOOL)animated 
{ 
NSArray *subviews = [self.view subviews]; 


    for (UIView *subview in subviews) { 

     [subview removeFromSuperview]; 

    } 
} 
1

viewWillDisappear您可以執行此任務,當您離開您的rootViewController時,此方法將會調用,因此您可以在此時刪除您的視圖。

-(void)viewWillDisappear:(BOOL)animated 
{ 
    for (UIView *view in [self.view subviews]) { 
     [view removeFromSuperview]; 
    } 
} 
1

在YourViewController的viewWillAppear:方法添加此

for (UIView *view in self.view.subviews) { 
     [view removeFromSuperview]; 
    } 

希望它可以幫助你

+0

'self.view.subviews'在迭代期間正在改變。這可能會導致某些系統的斷言。 – Andriy

0
[yourView removeFromSuperView] 

倒是subviews willnot是當你彈出一個UIViewController重,所以我不認爲你需要做的

+0

爲什麼在修復它們之後,將語法錯誤編輯回您的文章? –

+0

@ 0x7fffffff這不是正確語法的地方!如果可以,更好地發佈答案 –

+0

是的。也許你應該閱讀有關編輯權限:http://stackoverflow.com/privileges/edit –

2

在再回到動作,鍵入下面的代碼:

for (UIView *subview in self.view.subviews) { 
    [subview removeFromSuperview]; 
} 

,然後鍵入popToRootViewContoller

相關問題