0

我有PreviewController:UIViewController用于全屏显示文档,它是UINavigationViewController. 也是 的代表UISplitViewController

当它被推动时,它会隐藏masterView起来UISplitViewController。(方法 1 - 3 - 2 被调用)

当它消失时(通过按“返回”按钮),它显示masterView. UISplitViewController(调用方法 4 - 2)

但是有一种方法可以强制关闭PreviewController。在这种情况下,只有方法 4 被调用并被PreviewController释放,然后UISplitViewController才能发送消息并调用方法 2。

我该如何解决这个问题?有没有办法强制UISplitViewController调用它的委托方法?或者我可以PreviewController在方法 4 中保留并在方法 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]
4

1 回答 1

1

您当前没有对 PreviewController 实例持有任何强引用。在您的界面中添加一个强大的类属性就足够了:

@property (nonatomic, strong) PreviewController *previewVC;

然后使用以下命令创建实例:

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

这确保了 PreviewController 在您的视图控制器处于活动状态时不会被释放(除非您自己释放它)。

于 2013-11-15T10:45:22.930 回答