0

此自定义 segue 在视觉上可以正常工作,但完成时会出现警告。

Warning: Attempt to present <DestViewController: 0x21059f40> on <SrcViewController: 0x1fd50cf0> whose view is not in the window hierarchy!

任何有关如何在没有警告的情况下使其工作的帮助将不胜感激,在这方面花费的时间比我应该的要多。甚至不确定我是否应该关心它,因为这是一个警告。

- (void)perform {
    UIViewController *src = (UIViewController *)self.sourceViewController;
    UIViewController *dst = (UIViewController *)self.destinationViewController;

    dst.view.alpha = 0;

    [UIView animateWithDuration:0.5
                 animations:^{
                     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                     [src.view addSubview:dst.view];
                     dst.view.alpha = 1;
                 }
                 completion:^(BOOL finished){
                     [dst.view removeFromSuperview];
                     //need to understand why this throws a warning but still works
                     [src presentViewController:dst animated:NO completion:^(){
                         [src reset];
                     }];
                 }];
}

更新

在 src UIViewController 的 reset 方法中有一个停止 MPMoviePlayerController 的调用。出于某种原因导致该问题,一旦删除此 segue 就可以完美运行。有关 segue 的最终实现,请参阅下面的答案。

4

2 回答 2

0

您正在从 superview 中删除视图,即 src.view 并在它之后呈现相同的 viewController,因此它显示警告。

试试这个(如果这不起作用告诉我):

[UIView animateWithDuration:0.5
                 animations:^{
                     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                     dst.view.alpha = 1;
                 }
                 completion:^(BOOL finished){
                     [src presentViewController:dst animated:NO completion:^(){
                         [src reset];
                     }];
                 }];
}
于 2013-01-21T10:34:17.517 回答
0

虽然最初的问题是由 segue 之外的东西引起的,如上所述,我想我会为可能最终在这里的其他人发布完整的工作 segue 代码。此示例中的委托是一个自定义 UIViewController 容器,其中子 UIViewContainers 按以下方式添加为子项:

[self addChildViewController:childController_];
[self.view addSubview:childController_.view];

segue.h

#import <UIKit/UIKit.h>

@interface COFSimpleSegue : UIStoryboardSegue

@property (assign) UIViewController *delegate;

@end

segue.m

#import "COFSimpleSegue.h"
#import <QuartzCore/QuartzCore.h>

@implementation COFSimpleSegue

@synthesize delegate = delegate_;

- (void)perform {
    UIViewController *src = (UIViewController *)self.sourceViewController;
    UIViewController *dst = (UIViewController *)self.destinationViewController;

    dst.view.frame = delegate_.view.bounds;
    dst.view.autoresizingMask = delegate_.view.autoresizingMask;

    [src willMoveToParentViewController:nil];

    [delegate_
       transitionFromViewController:src
       toViewController:dst
       duration:0.5f
       options:UIViewAnimationOptionTransitionCrossDissolve
       animations:^(void){}
       completion:^(BOOL finished) {
         [dst didMoveToParentViewController:delegate_];
         [src removeFromParentViewController];
       }
    ];
}

@end
于 2013-02-14T22:30:17.043 回答