在以前版本的SWRevealViewController中,我创建了SWRevealViewControllerSegue class
的segue,在prepareforSegue
我使用了以下代码。
#pragma mark - Navigation
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] )
{
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
在新版本的SWRevealViewController中,没有segue SWRevealViewControllerSegue class.Instead有一个叫做的类 SWRevealViewControllerSetSegue。我创建了这个类的segue但是 导航没有发生。
以上代码不能在新版本中使用,因为它已弃用。我应该在prepareforSegue
使用什么?
我可以做些什么来执行导航?请帮助。
答案 0 :(得分:1)
请尝试以下代码
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SWRevealViewController *revealVC = (SWRevealViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"revealVCID"];
[self presentViewController:revealVC animated:YES completion:nil];
答案 1 :(得分:1)
你可以使用这个
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue isKindOfClass:[SWRevealViewControllerSegueSetController class] ]){
UIViewController *dvc = [segue destinationViewController];
UINavigationController *navCtrl = (UINavigationController *) self.revealViewController.frontViewController;
[navCtrl setViewControllers:@[dvc] animated:NO];
[self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
}
答案 2 :(得分:0)
这个适用于我
UIStoryboard *sb;
if (IS_IPAD) {
sb = [UIStoryboard storyboardWithName:@"iPad_Main" bundle:nil];
} else {
sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
}
if ([segue isKindOfClass:[SWRevealViewControllerSegueSetController class]]) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[[sb instantiateViewControllerWithIdentifier:@"create"]] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
答案 3 :(得分:-1)
Subhash Sharma的评论是正确的。我们不必编写准备导航的任何内容。
只需创建一个SWRevealViewControllerSeguePushController类型的segue 并在需要时执行此segue。它只是工作。