Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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)
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...