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):
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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…