2013-03-23 36 views
3

爲了測試和編寫代碼,我需要重新啓動我的GameViewContrller重新啓動的ViewController

GameViewController *controller = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil]; 
[self presentModalViewController:controller animated:NO]; 

這種方法重啓的viewController但所有存儲在內存中,因爲我的行爲/過程正在進行,作爲與每個而不是應用程序內存增加重啓。 我認爲這不是正確的方法,並且想知道如何完全覆蓋viewController以便於內存,刪除所有進程並重新啓動。

更新

- (IBAction)restartButtonPress { 
    // GameViewController *controller = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil]; 
    // [self presentModalViewController:controller animated:NO]; 

[self.view setNeedsDisplay]; 
} 
+0

wt你想要嗎? – iPatel 2013-03-23 10:49:18

+0

假設我有一個遊戲場景(遊戲場景描述都在gameview控制器中),因爲我必須重新啓動,因爲數據被寫入文件,我該如何實現它? – user2037857 2013-03-23 10:57:11

+0

你想重新啓動你的視圖? – iPatel 2013-03-23 10:58:11

回答

0

這只是開始一個新的。它不會重置舊的。

要刪除舊的,您需要撥打老號碼[controller release]

+0

比方說,我有一個遊戲場景(場景描述都在gameview控制器中)數據寫入文件,我該如何實現它? – user2037857 2013-03-23 10:57:56

2

致電[self.view setNeedsDisplay];用於重新加載您查看。您可以使用[self viewDidLoad]方法,但它不適合我們,也不會手動調用viewDidLoad。所以你可以使用setNeedsDisplay

+2

檢查我的更新信息,但不是什麼都沒有發生 – user2037857 2013-03-23 11:17:15

+0

@ user2037857-http://jomnius.blogspot.in/2010/05/how-to-reload-current-uiviewcontroller.html – iPatel 2013-03-23 11:38:26