Reputation: 1256
I just want to create custom segue so i have written below code. The code is seems fine but when i run this code it is giving below error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Subclasses of UIStoryboardSegue must override -perform.'
Below is the code:
#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
Any one please help me, What is wrong in this code.
Upvotes: 3
Views: 1898
Reputation: 1256
I have found the solution. For creating custom segue like above, We require to subclass UIStoryBoardSegue class and override the method perform. Below is the code that i have implemented.
#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];
}
This code will create the Push type animation and also solve above error.
Upvotes: 3