2012-03-01 1 views

답변

9

메인 뷰의 viewDidLoad에서 앱이 백그라운드로 전환되면 알림을 받도록 추가합니다.

- (void) viewDidLoad 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(goToBackground) 
     name:UIApplicationWillResignActiveNotification object:nil]; 
} 

goToBackground() 함수를 정의하십시오. 응용 프로그램이 백그라운드로 전환 될 때 호출됩니다

- (void) goToBackground 
{ 
    [self dismissModalViewControllerAnimated: NO]; // no need to animate 
} 

관찰자

- (void) dealloc 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 
을 제거하는 것을 잊지 마세요
1

알림을 사용할 수 있습니다. ApplicationDelegate의 메소드 applicationDidEnterBackground에서 알림을 게시하십시오. 모달 컨트롤러에서 닫기 메서드를 호출 할 수 있으므로 옵저버로 알림 센터에 추가하십시오.