2013-11-15 3 views
0

PreviewController : UIViewController이 문서를 전체 화면으로 표시하는 데 사용되는 부분은 UINavigationViewController입니다. 위임자는 UISplitViewController입니다.위임 메서드가 호출되기 전에 UIViewController가 할당 해제됩니다.

밀었을 때 masterViewUISplitViewController입니다.

"뒤로"버튼을 누르면 사라지고 은 UISplitViewController으로 표시됩니다. (방법 4 - 2가 호출됩니다)

그러나 닫는 방법은 PreviewController입니다. 이 경우 방법 4 만 호출되고 은 메시지를 보내고 방법 2를 호출하기 전에 PreviewController이 할당 해제됩니다.

이 문제를 어떻게 해결할 수 있습니까? UISplitViewController을 위임 메서드라고 부르는 방법이 있습니까? 또는 방법 4에서 PreviewController을 유지하고 방법 2에서이를 해제 할 수 있습니까 (ARC 사용)?

// Method 1 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.hideMaster = YES; 
    UISplitViewController *splitViewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController]; 
    splitViewController.delegate = self; 
} 

// Method 2 
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 
{ 
    return self.hideMaster; 
} 

// Method 3 
- (void)viewWillAppear:(BOOL)animated 
{ 
    self.hideMaster = YES; 
    UISplitViewController *splitViewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController]; 
    [splitViewController.view setNeedsLayout]; 
    [splitViewController willRotateToInterfaceOrientation:self.interfaceOrientation duration:0]; 
} 

// Method 4 
- (void)viewWillDisappear:(BOOL)animated 
{ 
    self.hideMaster = NO; 
    UISplitViewController *splitViewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController]; 
    [splitViewController.view setNeedsLayout]; 
    [splitViewController willRotateToInterfaceOrientation:self.interfaceOrientation duration:0]; 
} 

// PreviewController is created in UIViewController which belongs to UINavigationController 
PreviewController *previewVC = [[PreviewController alloc] initWithNibName:@"PreviewController" bundle:nil]; 
previewVC.documentURL = url; 
[self.navigationController pushViewController:previewVC animated:YES] 
+0

PreviewController 인스턴스는 어디에서 어떻게 생성됩니까? 그뿐 아니라 코드를 게시 할 수 있습니까? – Leijonien

+0

이 정보가 질문 섹션에 추가되었습니다. – GxocT

답변

1

현재 PreviewController 인스턴스에 대한 강력한 참조가 없습니다. 사용하여

@property (nonatomic, strong) PreviewController *previewVC; 

그리고 인스턴스를 만들 : 당신의 인터페이스에 강력한 클래스 속성을 추가하기에 충분합니다

self.previewVC = [[PreviewController alloc] initWithNibName:@"PreviewController" bundle:nil]; 

이것은 PreviewController을 보장 할당이 해제되지 않습니다 뷰 컨트롤러가있는 동안 살아있는 (당신이 그것을 풀어주지 않는 한).

+0

부분적으로 나를 도왔습니다. PreviewVC는 할당이 해제되지 않지만 대리자 메서드는 여전히 호출되지 않습니다. : – GxocT

+0

해결책을 찾았습니다. splitViewController.delegate = self;를 메서드 # 4에 추가했습니다. SplitViewController의 대리자가 다른 UIViewController에서 변경되었으므로 호출되지 않았습니다. – GxocT

관련 문제