在loginVC中我点击它创建了一个按钮,它会像这样进入主tabbarcontroller到segue ..
@IBAction func btnLoginPressed(sender: AnyObject) {
self.performSegueWithIdentifier("logintoMain", sender: self)
}
成功进入tabbarmainVC,但之后swRevealviewController变为nil ..并且滑动在这里不起作用。为什么呢?
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)
}
答案 0 :(得分:1)
尝试将其添加到此功能,看看会发生什么:
override func viewWillAppear(animated: Bool) {
if self.revealViewController() != nil{
slideBtn.target = self.revealViewController()
slideBtn.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
视图处于活动状态时会出现。