2009-09-22 4 views
0

내 주요 UIViewController (PMGameViewController.h)는 내 응용 프로그램에서 호출하는 파일입니다.iPhone - Multiple UIViewControllers Release

메인 UIViewController (PMGameViewController.m)에는 여러 개의 버튼이 있습니다. 버튼을 누르면 insertSuvbiew를하고 위에 다른 UIViewController를 첨부합니다. 미니 게임이 끝나면 removeFromSubview 만 수행하면됩니다. 이것은 상단에 삽입 된 UIViewController를 제거하고 메인 메뉴를 보여줍니다. 내가 원하는 것은 완벽하지만 ...

removeFromSubview를 수행 한 후에 objectalloc이 삭제되지 않습니다. 해당 UIViewController 메모리를 어떻게 발표 할 수 있습니다. 나는 그것이 제거되었고 UIViewController 메모리를 해제한다는 것을 알기 위해 주 UIViewController (PMGameViewController.m)에 역 참조 할 수있는 방법을 모른다. 당신이 그것을 제거 후에는 전무로 뷰 컨트롤러를 설정할 수있는 하위 뷰를

////////////////////////////////////// 
//Buttons are in PMGameViewController.m file 
////////////////////////////////////// 

if((UIButton *) sender == gameClassicBtn) { 
     ////////////////////////////////////// 
     //This Inserts the GameClassic.h file 
     ////////////////////////////////////// 
     GameClassic *gameClassicController = [[GameClassic alloc] 
              initWithNibName:@"GameClassic" bundle:nil]; 
     self.gameClassic = gameClassicController; 
     [gameClassicController release]; 
     [self.view insertSubview:gameClassicController.view atIndex:1]; 
    } 

if((UIButton *) sender == gameArcadeBtn) { 
     ////////////////////////////////////// 
     //This Inserts the GameArcade.h file 
     ////////////////////////////////////// 
     GameArcade *gameArcadeController = [[GameArcade alloc] 
              initWithNibName:@"GameArcade" bundle:nil]; 
     self.gameArcade = gameArcadeController; 
     [gameArcadeController release]; 
     [self.view insertSubview:gameArcadeController.view atIndex:1]; 
    } 
+0

당신이 돈을 우리 대답이 싫어? 코멘트가 없습니까? – Julien

답변

0

을 삽입하는 방법은 다음과

이다. nil로 설정하기 전에 선택적으로 해제 할 수 있습니다. 출시 여부는 사용 방법 및로드 비용에 따라 다릅니다.

1

나중에 PGGameViewController가 필요할 수 있기 때문에 왜 이것을하고 싶은지 모르겠다. 당신이 정말로 그것을 해제하려는 경우, 당신은이 작업을 수행 할 수 있습니다 :

PMGameViewController *tmpViewController = [[[UIApplication sharedApplication] delegate] viewController(or however it's called)] 

다음, 그것을 역 참조 물건을하고 당신이 그것을 필요로하지 않을 때 분리합니다 :

[tmpViewController release] 

당신이있는 경우 잠시 동안 참조를 유지하기 위해, 당신은 당신이 개 게임이 컨트롤러를 볼에 아이디 바르를 생성 및 asign 프로토콜을 사용하지만, 컨트롤러 출시 이후 전무로 설정하는 것을 잊지 마세요 수 :

id tmpViewController; 
... 
@property (nonatomic, assign) id tmpViewController; 
... 
@synthesize tmpViewController;