2011-05-02 8 views
0

4 개의보기가있는 앱이 있습니다. HomeView, PreGameView, GameView, PostGameView. 응용 프로그램은 HomeView에서 시작하는 방식으로 작동합니다. 그런 다음 PreGameView로 이동하는 시작을 클릭하고, GameView로 나를 데려가는 시작을 클릭하고, 최종 게임에서 PostGameView로 이동합니다.이 게임을 통해 다시 돌아갈 수 있습니다. GameView 또는 HomeView로 돌아갑니다.presentModalViewController를 올바르게 사용하고 있습니까? 도움?

"presentModalViewController"메서드를 사용하여 이러한 뷰를 레이어합니다. 그러나 PostGameView까지 모든 레이어를 쌓은 다음 HomeView로 돌아 가려고 결정하면 화면이 그냥 흰색으로 바뀝니다.

나는 또한 다음을 제시하기 전에 각 modelview를 해고하려고 시도했지만 작동하지 않으며 앱이 모두 혼란스러워집니다. 누구든지 올바른 방법을 알고 있습니까? 도와주세요?

HomeView.m

- (IBAction)loadPreGameView:(id)sender { 
    PreGameView *preGameView = [[PreGameView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:preGameView animated:YES]; 
} 

PreGameView.m

- (IBAction)loadGameView:(id)sender { 
    GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:gameView animated:NO]; 
} 

GameView.m

- (IBAction)loadPostGameView:(id)sender { 
    PostGameView *postGameView = [[PostGameView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:postGameView animated:NO]; 
} 

PostGameView.m

- (IBAction)loadGameView:(id)sender { 
    GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:gameView animated:NO]; 
} 

- (IBAction)loadHomeView:(id)sender { 
    HomeView *homeView = [[HomeView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:homeView animated:NO];  
} 

나는 또한 내 PostGameView.m의 아래를했지만, 그것은 단지 뒤에 GameView 보여 주었다 :

PostGameView.m (구)

- (IBAction)loadGameView:(id)sender { 
    GameView *gameView = [[GameView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:gameView animated:NO]; 
} 

- (IBAction)loadHomeView:(id)sender { 
    [self dismissModalViewControllerAnimated:YES]; 
} 

답변

1

훨씬 더 나은 접근 방법은 UINavigationController를 사용하여이를 수행하는 것입니다.

거기에서 HomeView 로 ... init을하는 UINavigationController가 만들기 [self.navigationController과 pushViewController : nextViewController 애니메이션 : NO]

작업을 완료하고 처음 [self.navigationController popToRootViewControllerAnimated에 POP하고자하는

: NO ];

NavController 사용에 대한 좋은 점은 각 UIViewController가 자동으로 NavController에 대한 참조를 보유한다는 것입니다. self.navigationController;

전체 화면을 원할 경우 탐색 모음을 해제 할 수도 있습니다.

또한 UINavigationController는 ViewController를 유지하므로 "Push"한 후에 사용자가 만든 모든 UIViewController에서 release를 호출해야합니다.

0

보기 컨트롤러 체인이 있습니다. 학부모에게 다시 연락하려면 각 레벨에서 퇴장해야합니다. 여러 단계 위로 올라가서 해고하면 아래의 모든 아이들이 나옵니다. 뷰 컨트롤러를 할당하거나 명시 적으로 해제 한 후에 뷰 컨트롤러를 자동으로 릴리스해야하므로 memleak을 가질 수도 있습니다.

+0

하지만 내가 [self dismissModalViewControllerAnimated : NO] 할 때; GameView * gameView = [[GameView alloc] initWithNibName : nil 번들 : nil]; PreGameView.m에서 [self presentModalViewController : gameView animated : NO];'보기는 GameView가 아닌 ​​PreGameView에서 다시 HomeView로 돌아갑니다. – buzzkip

관련 문제