在loginVC中,我创建了一个按钮,点击它后,通过segue跳转到主tabbarcontroller,如下所示...
@IBAction func btnLoginPressed(sender: AnyObject) {
self.performSegueWithIdentifier("logintoMain", sender: self)
}
成功跳转到tabbarmainVC,但之后swRevealviewController为空,因此滑动功能无法使用。为什么会这样呢?
class MaintabbarController: UIViewController{
@IBOutlet weak var slideBtn: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if self.revealViewController() != nil{
slideBtn.target = self.revealViewController()
slideBtn.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
编辑
我也尝试了在登录按钮点击时使用这段代码以进入mainTabbarvc。现在它可以正常工作。实际上,我必须推送revealviewController才能使其生效。
@IBAction func btnLoginPressed(sender: AnyObject) {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc =sb.instantiateViewControllerWithIdentifier("yourtabbarvcidentifier") as! UITabBarController
vc.selectedIndex = 0
// self.presentViewController(vc, animated: true, completion: nil)
self.revealViewController().pushFrontViewController(vc, animated: true)
}