iOS - TableViewController e SWRevealViewController for menu

谁说胖子不能爱 提交于 2019-12-13 02:59:05

问题


In my tableview I inserted a barbutton item inside the Navigation Controller as in the photo Which at the pressure must open a side menu

The problem is that I do not open any menus! I follow this video: https://www.youtube.com/watch?v=wXCHDP9V3aM&t=188s

It looks like the tableview does not recognize the button pressure .. what can I do?


回答1:


The most convenient to be a reason for the revealViewController to be nil is you didn't connect segues correctly in stroyboard.

If TabViewController is not your storyboard entry point then add this code in AppDelegate. AppDelegate :

if (userDefaults.object(forKey:"user") != nil) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    self.window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController")
    self.window?.makeKeyAndVisible()
}

Or If you are presenting the TabViewController for other viewController then use this code to present TabViewController.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let main = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") //SWRevealViewController
self.present(main, animated: true, completion: nil)

Update :

  1. You need to separate loginViewController and TabViewController as in the below image.(No segue between both)

  1. Add SWRevealViewController and Menu screen tableview.
  2. Next, control-drag from SWRevealViewController to the Menu view controller. After releasing the button, you will see a context menu for segue selection. In this case, select “reveal view controller set segue”. This defines a custom segue “SWRevealViewControllerSetSegue”. Select the segue and change its identifier to “sw_rear” under the Identity inspector. By setting the identifier, you tell SWRevealViewController that the menu view controller is the rear view controller. In this case, the sidebar menu will be hidden behind a content view controller.
  3. Next, repeat the same procedures to connect SWRevealViewController with the navigation controller of the news view controller. Again, select “reveal view controller set segue” when prompted. Set the identifier of the segue to “sw_front”. This tells the SWRevealViewController that the navigation controller is the front view controller.
  4. same with tableview controller to main view controller just select segue as reveal view controller push.
  5. Add this code in all tabs.

    if (self.revealViewController() != nil) {
    menuButton.target = self.revealViewController()
    menuButton.action =  #selector(SWRevealViewController.revealToggle(_:))
    self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
    }
    
  6. After Login Jump to TabViewController use this code.

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let main = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") //SWRevealViewController
    self.present(main, animated: true, completion: nil)
    
  7. After login : To skip login view add this check in AppDelegate : AppDelegate :

    if (userDefaults.object(forKey:"user") != nil) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    self.window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController")
    self.window?.makeKeyAndVisible()
    }
    


来源:https://stackoverflow.com/questions/44779396/ios-tableviewcontroller-e-swrevealviewcontroller-for-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!