【问题标题】:Storyboard: 'Subclasses of UIStoryboardSegue must override -perform.'故事板:'UIStoryboardSegue 的子类必须覆盖 -perform。'
【发布时间】:2015-02-02 10:03:42
【问题描述】:

我只想创建自定义 segue,所以我写了下面的代码。代码看起来不错,但是当我运行这段代码时,它给出了以下错误:

由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'子类 UIStoryboardSegue 必须覆盖 -perform。'

下面是代码:

#import "ViewController.h"
#import "Temp-2.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 Temp_2 *toViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Temp2"];
 segue1=[[UIStoryboardSegue alloc] initWithIdentifier:@"temp" source:self destination:toViewController];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)actionPush:(id)sender {

 [self prepareForSegue:segue1 sender:sender];
 [segue1 perform];
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
 if ([segue1.identifier isEqualToString:@"temp"])
 {
     [segue1.destinationViewController setStr:@"string passed"];

 }
}
 @end

任何人请帮助我,这段代码有什么问题。

【问题讨论】:

    标签: ios storyboard xcode6 uistoryboardsegue


    【解决方案1】:

    我找到了解决方案。为了创建像上面这样的自定义 segue,我们需要继承 UIStoryBoardSegue 类并覆盖方法 perform。下面是我实现的代码。

    #import "MyCustomSegue.h"
    
    @implementation MyCustomSegue
    - (void)perform
    {
    UIViewController *source = self.sourceViewController;
    UIViewController *destination = self.destinationViewController;
    
    UIWindow *window = source.view.window;
    
    CATransition *transition = [CATransition animation];
    [transition setDuration:1.0];
    [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [transition setType:kCATransitionPush];
    [transition setSubtype:kCATransitionFromRight];
    [transition setFillMode:kCAFillModeForwards];
    [transition setRemovedOnCompletion:YES];
    
    
    [window.layer addAnimation:transition forKey:kCATransition];
    [window setRootViewController:destination];
    }
    

    此代码将创建 Push 类型的动画并解决上述错误。

    【讨论】:

      猜你喜欢
      • 2014-07-29
      • 1970-01-01
      • 2016-01-09
      • 2010-12-16
      • 2012-01-20
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多