有没有办法在prepareForSegue中更改segue将要调用的控制器?我正在尝试在嵌入式segue中更改分段控件时实现这个功能。谢谢!
@interface ViewController : UIViewController
@property (weak,nonatomic) IBOutlet UIView *container;
@property (strong,nonatomic) UIViewController *initialVC;
@property (strong,nonatomic) UIViewController *substituteVC;
@property (strong,nonatomic) UIViewController *currentVC;
@end
这是我在ViewController.m中的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.initialVC = self.childViewControllers.lastObject;
self.substituteVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Substitute"];
self.currentVC = self.initialVC;
}
-(IBAction)SwitchControllers:(UISegmentedControl *)sender {
switch (sender.selectedSegmentIndex) {
case 0:
if (self.currentVC == self.substituteVC) {
[self addChildViewController:self.initialVC];
self.initialVC.view.frame = self.container.bounds;
[self moveToNewController:self.initialVC];
}
break;
case 1:
if (self.currentVC == self.initialVC) {
[self addChildViewController:self.substituteVC];
self.substituteVC.view.frame = self.container.bounds;
[self moveToNewController:self.substituteVC];
}
break;
default:
break;
}
}
-(void)moveToNewController:(UIViewController *) newController {
[self.currentVC willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentVC toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{}
completion:^(BOOL finished) {
[self.currentVC removeFromParentViewController];
[newController didMoveToParentViewController:self];
self.currentVC = newController;
}];
}