Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

ios - SWRevealViewController - Reveal not showing nav menu

I'm following this tutorial and I'm at the point (about halfway down) where I add this bit of code to some sort of controller:

if self.revealViewController() != nil {
    menuButton.target = self.revealViewController()
    menuButton.action = "revealToggle:"
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}

Now, I'm a little confused on where this piece of code goes. I currently have it in my "front" view (the one that shows when the menu is closed). However, when I click my menu button, nothing happens.

Here is what my current storyboard looks like (there is a white menu button left of "Home" on the home screen, hard to see):

enter image description here

And here is my current viewDidLoad function inside HomeViewController.Swift:

override func viewDidLoad() {
        super.viewDidLoad()

        if self.revealViewController() != nil {
            print("reveal")
            menuButton.target = self.revealViewController()
            menuButton.action = "revealToggle:"
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }


        if webView != nil {
            print("webview is not null")
            webView!.scrollView.bounces = false

            let path = NSBundle.mainBundle().pathForResource("find_it_myself", ofType: "html", inDirectory: "assets/html/home")
            let serviceDeskPath = NSBundle.mainBundle().pathForResource("ServiceDeskNumbers", ofType: "json", inDirectory: "assets/data")
            let serviceDeskData = NSData(contentsOfMappedFile: serviceDeskPath!)
            let serviceCenterPath = NSBundle.mainBundle().pathForResource("ITSC Live Room Locations", ofType: "json", inDirectory: "assets/data")
            let serviceCenterData = NSData(contentsOfMappedFile: serviceCenterPath!)

            let newStr = NSString(data: serviceDeskData!, encoding: NSUTF8StringEncoding)
            let newerStr = NSString(data: serviceCenterData!, encoding: NSUTF8StringEncoding)

            NSLog(String(webView!.URL))



            NSLog("path: " +  path!)
            let requestURL = NSURL(fileURLWithPath: path!)
            print("request is not null")
            let request = NSURLRequest(URL:requestURL)

            let theConfiguration = WKWebViewConfiguration()
            theConfiguration.userContentController.addScriptMessageHandler(self, name: "interOp")

            webView!.loadRequest(request)
        }
        else{

            print("webview is null")
        }



    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'll post my solution just in case. The reveal was actually working, but only with the sliding gesture, not by pressing the menu button.

I added a button press function for the menuButton, with a revealToggle function call to the library from the GitHub project (SWRevealViewController).

@IBAction func menuButtonPressed(sender : AnyObject){
        self.revealViewController().revealToggle(menuButton)
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...