gpt4 book ai didi

ios - Storyboard:“UIStoryboardSegue的子类必须覆盖-perform。”

转载 作者:行者123 更新时间:2023-12-01 16:03:45 26 4
gpt4 key购买 nike

我只想创建自定义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

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

最佳答案

我找到了解决方案。为了创建上述的自定义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型动画,并解决上述错误。

关于ios - Storyboard:“UIStoryboardSegue的子类必须覆盖-perform。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27295493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com