[英]Manual segue with SWRevealViewController in Swift
There is a great blog post over at http://www.appcoda.com/tag/swrevealviewcontroller/ that goes in to setting up SWRevealViewController which is a great component for slide out side menus ( https://github.com/John-Lluch/SWRevealViewController ) 在http://www.appcoda.com/tag/swrevealviewcontroller/上有一篇很棒的博客文章,其中介绍了设置SWRevealViewController,它是滑出侧边菜单的一个很好的组件( https://github.com/John- Lluch / SWRevealViewController )
Unfortunately, there are no swift examples of how to perform a manual segue. 不幸的是,没有关于如何执行手动segue的快速示例。
Took a cleaner approach to storyboard support.
对故事板支持采取更清晰的方法。 SWRevealViewControllerSegue is now deprecated and you should use SWRevealViewControllerSegueSetController and SWRevealViewControllerSeguePushController instead.
现在不推荐使用SWRevealViewControllerSegue,您应该使用SWRevealViewControllerSegueSetController和SWRevealViewControllerSeguePushController。
I've tried something along the lines of: 我尝试过以下方面:
let navigationController = self.window?.rootViewController as! SWRevealViewController;
let viewController = navigationController.storyboard?.instantiateViewControllerWithIdentifier("ImportFileSelect") as! ImportFileSelect
navigationController.showViewController(viewController, sender: self)
This doesn't work though. 但这不起作用。 Any ideas?
有任何想法吗? I've trawled the web for swift examples, my next step is to learn objective c!
我已经在网上搜索了一些快速的例子,我的下一步是学习目标c!
In order to work you'll need to following steps: 为了工作,您需要执行以下步骤:
Finally push the navigation controller with SWReveal 最后用SWReveal推送导航控制器
let storyboard = UIStoryboard(name: "Main", bundle: nil) let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController self.view.window?.rootViewController = sw let destinationController = self.storyboard?.instantiateViewControllerWithIdentifier("StoryboardID") as! NameOfViewController let navigationController = UINavigationController(rootViewController: destinationController) sw.pushFrontViewController(navigationController, animated: true)
I've kind of made some progress. 我有点进步了。 I can load in a new view controller, but it doesn't animate in anyway.
我可以加载一个新的视图控制器,但无论如何它都没有动画。 The code to do this, on a button click is:
单击按钮时执行此操作的代码为:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("TARGET_VIEW_CONTROLLER") as! UIViewController
var rvc:SWRevealViewController = self.revealViewController() as SWRevealViewController
rvc.pushFrontViewController(vc, animated: true)
This is not how it should be done, but at least i found a way to do it. 这不是应该怎么做,但至少我找到了一种方法来做到这一点。
In the TableViewController where u have the slideOut menu do something like: 在TableViewController中你有slideOut菜单做类似的事情:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.row == <some position> ){
let vc: AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_DESTINATION_IDENTIFIER")
self.showViewController(vc as! SWRevealViewController, sender: vc)
}
The one that satisfy the condition will segue with default animation, not like the slide out menu normally does. 满足条件的那个将使用默认动画进行segue,而不像幻灯片菜单通常那样。
After, in storyboard, do a normal Reveal View Controller Push controller, and as long as it doesn't satisfy the condition it will exit the slide out menu normally 在故事板中,执行一个普通的Reveal View Controller Push控制器,只要它不满足条件,它就会正常退出滑出菜单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.