SWRevealViewController和3D Touch quickActions

时间:2015-10-17 23:14:51

标签: swrevealviewcontroller quickaction 3dtouch

我有一个在swift中实现侧边菜单的应用程序。 (http://www.appcoda.com/sidebar-menu-swift/

我实现了3D触控快捷键,快速操作,几乎可以正常工作。

问题是我直接到达我的视图而没有实例化revealViewController(),使用以下代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let navVC = storyboard.instantiateViewControllerWithIdentifier("newsViewController") as! UINavigationController
self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)

我不知道如何/在哪里实例化revealViewController()。

我有:

self.revealViewController() == nil 

现在发生的是菜单不想打开。

感谢您的帮助: - )

4 个答案:

答案 0 :(得分:2)

您可以在此链接中找到答案: How to push viewcontroller from appdelegate in storyboard

我Worte代码如下所示它对我有用。

    UIStoryboard *st = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    SWRevealViewController *mainRevealController = [[SWRevealViewController alloc] init];
    CaseCollectionViewController *descController = (CaseCollectionViewController*)[st instantiateViewControllerWithIdentifier: @"CaseCollection"];
    descController.selectedLevel = @"pll";
    descController.title = @"PLL";

    //UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:descController];
    UINavigationController *frontNavigationController = (UINavigationController*)[st instantiateViewControllerWithIdentifier: @"NavigationViewCtrl"];
    [frontNavigationController setViewControllers:@[descController]];
    SidebarTableViewController *rearViewController = (SidebarTableViewController*)[st instantiateViewControllerWithIdentifier: @"SideBarView"];
    mainRevealController.rearViewController = rearViewController;
    mainRevealController.frontViewController = frontNavigationController;
    self.window.rootViewController = mainRevealController;

答案 1 :(得分:1)

对于那些想用Swift做的人:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let frontNavigationController = storyboard.instantiateViewControllerWithIdentifier("planningViewController")
let rearNavifationController = storyboard.instantiateViewControllerWithIdentifier("menuViewController")
let mainRevealController : SWRevealViewController = SWRevealViewController(rearViewController: rearNavifationController, frontViewController: frontNavigationController)
self.window?.rootViewController? = mainRevealController

答案 2 :(得分:0)

为了让你的显示ViewControlled你必须在故事板中将它作为InitialViewController,不需要在Appdelgate中编写任何代码。

您可以在git hub storyboard example中找到最佳示例 要么 设置如下屏幕截图 enter image description here

答案 3 :(得分:0)

用于深度链接的Objective-c代码。它将打开带有侧边菜单的主页,并将主页(前视图控制器)推送到通知视图控制器。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *frontViewControllerNav = [storyboard instantiateViewControllerWithIdentifier:@"homeNav"];// navigation controller of home screen..
UINavigationController *rearViewControllerNav = [storyboard instantiateViewControllerWithIdentifier:@"sideMenuNav"];//navigation controller of menu screen..

SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewControllerNav frontViewController:frontViewControllerNav];
revealController.delegate = self;
UIViewController *notificationView=[storyboard instantiateViewControllerWithIdentifier:@"notificationVC"];
[frontViewControllerNav pushViewController:notificationView animated:NO];
revealController.bounceBackOnOverdraw=NO;
//revealController.stableDragOnOverdraw=YES;
self.window.rootViewController = revealController;