Ios 如何通过单击按钮打开SWRevealViewController?

Ios 如何通过单击按钮打开SWRevealViewController?,ios,objective-c,xcode,mobile,xcode6,Ios,Objective C,Xcode,Mobile,Xcode6,我是XCode/iOS开发的新手,我正在尝试创建一个导航菜单。我紧随其后,设法使它发挥作用。当SWRevealViewController是初始视图控制器时,它会打开 现在,我有一个带有按钮的登录页,当我点击它时,我希望它被导航到SWRevealViewController 我试着用这些代码打开SWRevealViewController,在单击按钮时执行此操作,但它没有显示,并且这些代码在其他UIViewController上工作 SWRevealViewController*菜单=[[SWR

我是XCode/iOS开发的新手,我正在尝试创建一个导航菜单。我紧随其后,设法使它发挥作用。当SWRevealViewController是初始视图控制器时,它会打开

现在,我有一个带有按钮的登录页,当我点击它时,我希望它被导航到SWRevealViewController

我试着用这些代码打开SWRevealViewController,在单击按钮时执行此操作,但它没有显示,并且这些代码在其他UIViewController上工作

SWRevealViewController*菜单=[[SWRevealViewController alloc]init];
[self.navigationController pushViewController:菜单动画:是]

有人能指导我为什么以及如何实现我想要的吗?这可能是个愚蠢的问题,但我需要帮助。提前谢谢


请检查以下代码。我希望这对你有帮助

第1步:只需为您的SWRevealViewController提供情节提要引用,然后在您的按钮操作中编写以下代码

在Objective-C中

 SWRevealViewController *revealVC = [self.storyboard instantiateViewControllerWithIdentifier:@"swRevealViewContoller"];
                revealVC.delegate=self;
 [[UIApplication sharedApplication]keyWindow].rootViewController = revealVC;
在Swift中:

//MARK: searchBtnClicked
@IBAction func searchBtnClicked(sender: AnyObject) {
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("swRevealViewContoller") as? SWRevealViewController
     UIApplication.sharedApplication().keyWindow!.rootViewController = nextViewController;
}
如果您正面临此类问题,只需将其视为“rootViewController”,然后享受编码的乐趣。

使用此选项

let myRevealViewControl:SWRevealViewController = self.revealViewController()
    let myStoryBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let myDest = myStoryBoard.instantiateViewController(withIdentifier: "homePage") as! UIViewController
    let myNewFrontView = UINavigationController.init(rootViewController: myDest)
    myRevealViewControl.pushFrontViewController(myNewFrontView, animated: true)
你可以这样做:

menuButton.addTarget(revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), for: .touchUpInside)

显示屏幕截图,我不会进入你的point@Anbu.Karthik按要求上传屏幕截图。对不起,字体太小了。第一个是带有按钮的视图控制器。第二个是SWRevealViewController。它应该是push,而不是替换根视图本身。如果SWRevealViewController本身在不同的故事板中,self.revealViewController()将无法工作。有其他解决办法吗?