2

내 상태를 응용 프로그램에 통합하려고합니다. 나는 대부분 잘 작동하지만, 다른 네비게이션 컨트롤러 위에 모달 뷰를위한 네비게이션 컨트롤러를 제시하는 것은 어려운 일이다.iOS 상태 복원 및 UINavigationController 모달보기

테스트를 위해 iPad에서 분할보기 양쪽에 탐색 컨트롤러가있는 새 분할보기 응용 프로그램을 만들고 각각의 탐색 컨트롤러의 뿌리 인 양쪽에 대한 마스터 및 세부보기 컨트롤러를 만들었습니다. 마스터 뷰에서 버튼을 클릭하여 새로운 TestViewController를 navController 스택에 프로그래밍 방식으로 푸시 (push) 할 수 있습니다. 스토리 보드에서 splitView를 연결하고, 모든 것에 restorationID를 추가하고, 델리게이트에 옵트 인하고, 복원 클래스를 제공하고, TestViewController의 UIViewControllerRestoration 프로토콜을 준수합니다 (프로그래밍 방식으로 생성되기 때문에). 모든 것이 잘 작동합니다. 앱을 닫고 레토르트하면 마스터의 navcontroller에 푸시 된 TestViewController가 시작됩니다. 여태까지는 그런대로 잘됐다.

그런 다음 단추 탐색기를 변경하여 TestViewController를 새 UINavigationController 내에 표시하고 마스터의 탐색 컨트롤러에 표시하여 모달보기를 표시합니다 (nav 스택에 푸시하는 대신). 이제 앱을 다시 시작하면 더 이상 모달보기가 없습니다. TestModalViewController의 viewControllerWithRestorationIdentifierPath : 코더 : 실제로 이전처럼 올바르게 호출되지만 모달 뷰는 어떤 이유로 든 표시되지 않습니다.이

- (void)pushButton:(id)sender 
{ 
    TestModalViewController *test = [[TestModalViewController alloc] initWithNibName:@"TestViewController" bundle:nil]; 
    test.restorationIdentifier = @"testid"; 
    test.restorationClass = [TestModalViewController class]; 

    UINavigationController *modal = [[UINavigationController alloc] initWithRootViewController:test]; 
    modal.modalPresentationStyle = UIModalPresentationFormSheet; 
    modal.restorationIdentifier = @"ModalTestID"; 
    [self.navigationController presentViewController:modal animated:YES completion:nil]; 
    return; 
} 

TestModalViewController.m :

+ (UIViewController *) viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder { 
    TestModalViewController *test = [[TestModalViewController alloc] initWithNibName:@"TestViewController" bundle:nil]; 
    test.restorationClass = [TestModalViewController class]; 
    test.restorationIdentifier = [identifierComponents lastObject]; 
    return test; 
} 

아마도 UINavigationController가가 여기에

내가 약

MasterViewController.h을 무슨 말인지 코드입니다 모달로 표시되도록 생성 된 내용이 보존되지 않습니까? 왜 RestorationIdentifier가 없기 때문에 이유를 모르겠습니다.

편집 : 코드, 직접, 제대로 복원 가져옵니다 TestModalViewController 인스턴스를 제시 : 나는 푸시 버튼에서 UINavigationController가를 제거하는 경우

추가 시험 후에는 밝혀졌습니다. 그래서 뭔가 다른 UINavigationController에서 제시되는 UINavigationController에 대해?

(정말 원하지 무엇을하지만)이 작동 :

- (void)pushButton:(id)sender 
{ 
    TestModalViewController *test = [[TestModalViewController alloc] initWithNibName:@"TestViewController" bundle:nil]; 
    test.restorationIdentifier = @"testid"; 
    test.restorationClass = [TestModalViewController class]; 

    //UINavigationController *modal = [[UINavigationController alloc] initWithRootViewController:test]; 
    //modal.modalPresentationStyle = UIModalPresentationFormSheet; 
    //modal.restorationIdentifier = @"ModalTestID"; 
    [self.navigationController presentViewController:test animated:YES completion:nil]; 
    return; 
} 

편집 : 테스트 프로젝트에 첨부 링크 : 그것은 기본적으로 코어 데이터 마스터 - 세부 템플릿의 dropbox.com/sh/w8herpy2djjl1kw/vw_ZWqimgt

을; iPad 시뮬레이터에서 실행하십시오. 마스터의 + 버튼은 TestModalVC를 호출합니다. 그런 다음 홈 버튼을 누른 다음 디버거를 종료하고 다시 시작하면 스냅 샷에 TestModalVC가 포함되어 있지만 응용 프로그램이 시작되면 복원되지 않습니다.

+0

샘플 프로젝트를 첨부 할 수 있습니까? –

+0

여기 링크가 있습니다 : https://www.dropbox.com/sh/w8herpy2djjl1kw/vw_ZWqimgt –

답변

0

이 문제를 처리하기 위해 자체 복원 클래스를 만들 수 있습니다 또는 앱 위임에 다음을 추가하십시오 documentation

- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents 
coder:(NSCoder *)coder 
{ 
    NSString *lastIdentifier = [identifierComponents lastObject]; 
    if ([lastIdentifier isEqualToString:@"ModalTestID"]) 
    { 
     UINavigationController *nc = [[UINavigationController alloc] init]; 
     nc.restorationIdentifier = @"ModalTestID"; 
     return nc; 
    } 
    else if(...) //Other navigation controllers 
    { 
    } 

    return nil; 
} 

더 많은 정보를.

+0

고마워요. 그러나 샘플을 보면 TestModalViewController에 restorationClass 및 restorationIdentifier가 설정되어 있습니다. 그러나 UINavigationController 같은 규칙에 의해 재생되지 않는 것 같습니다. viewControllerWithRestorationIdentifierPath가 작동하는지 테스트 해 보겠습니다. –

+0

@ZS 문제는 'TestModalViewController'가 아니며 탐색 컨트롤러입니다. 클래스를 설정하지 않으면 시스템은 마지막 수단 인 앱 위임을 시도합니다. –

+0

감사합니다. 그것은 부분적으로 작동합니다. 유일한 UIApplication viewControllerWithRestorationIdentifierPath는 모든 restorationID에 대해 쿼리됩니다. 그래서 다른 식별자 (예 : splitView, 마스터 뷰, 세부 뷰 등)를 반환하지 않으면 대신 nil을 반환 할 것입니다. 어떻게하면 기본적으로 복원 클래스를 사용하게하고 UINavigationController의 기본값으로 만 사용합니까? 또는이 클래스의 viewControllerWithRestorationIdentifierPath에서 모든 코드를이 UIApplication 대리자 viewControllerWithRestorationIdentifierPath : –