I have two view controllers involved in this issue. The first is "eatMap" and the second is "restaurants." eatMap contains multiple buttons that show pictures and names of restaurants as well as a map with pins of each location. I want the restaurants View Controller to display the the menus of each restaurant in a UIWebView called "eatView". I have an array holding the urls to each website.
How do I instruct the UIWebView to load a different url depending on which button is clicked?
I suspect the problem is in my prepareForSegue function or with my var currentSite or var url, but I'm not sure. I know the urls aren't being passed correctly into theUIWebView.
I'm stuck!
Sorry for all the backslashes. I've been trying to keep track of what all I've tried that has gotten me anywhere.
here is View Controller 1 aka eatMap:
import UIKit
import MapKit
class eatMap: UIViewController {
var siteLink = ["http://amici-cafe.com/athens.html", "http://www.athensbagel.com/", "https://www.facebook.com/dawggonegoodbbq/", "http://www.fuzzystacoshop.com/", "http://places.singleplatform.com/globe/menu?ref=google", "https://www.facebook.com/Kellys-Authentic-Jamaican-Food-333515583330794/", "http://theplaceathens.com/", "http://www.pauleyscrepebar.com/", "http://southkitchenbar.com/", "http://tazikiscafe.com/", "http://www.tedsmostbest.com/", "https://yourpie.com/", "http://trappezepub.com/", "http://www.vivaargentinecuisine.com/", "http://five-bar.com/bar-locations/athens-georgia/"]
var currentSite = 0
var url = String()
@IBAction func button01(_ sender: Any) {
currentSite=0
//var url = NSURL(string: currentSite = 0)
//var url = NSURL(string: siteLink[0])
//loadPage()
}
@IBAction func button02(_ sender: Any) {
currentSite+=1
//var url = NSURL(string: currentSite = 1)
//var url = NSURL(string: siteLink[1])
//loadPage()
}
@IBAction func button03(_ sender: Any) {
currentSite+=2
//var url = NSURL(string: currentSite = 2)
// var url = NSURL(string: siteLink[2])
//loadPage()
}
//func loadPage(){
//let url = NSURL(string: self.url)
//(string: siteLink[currentSite])
//let request = NSURLRequest(url:url as! URL)
//self.eatView.loadRequest(request as URLRequest)
//}
@IBOutlet weak var mainScrollView: UIScrollView!
var myTitles = ["Amici", "Athens Bagel Co.", "Dawg Gone Good BBQ", "Fuzzy's Taco Shop", "The Globe", "Kelly's Jamaican Foods", "The Place", "Pauley's", "South Kitchen and Bar", "Taziki's", "Ted's Most Best", "Your Pie", "Trappeze Pub", "Viva Argentine Cuisine", "FIVE Athens"]
var mySubtitles = ["Casual Italian dining", "Bagels", "No-nonsense outpost for BBQ & sides", "Sleek Mexican counter-service chain", "Laid-back hangout with pub grub & beer", "Unfussy stop for jerk chicken & curries", "Chill Southern choice with craft beer", "Crepes & craft beer at a casual cafe/bar", "Classy setting for modern Southern eats", "Informal stop for Mediterranean fare", "Italian kitchen in an old garage space", "PBrick-oven pizza & craft beers on tap", "Craft beer & reimagined pub fare", "Guess what kind of food", "Stylish New American eatery & bar"]
var latLong = [[33.960148,-83.375147],[33.959384,-83.374598],[33.958231, -83.377229],[33.939764, -83.385928],[33.957978, -83.374932],[33.958086, -83.376514],[33.959761, -83.375207],[33.960177, -83.382644],[33.958810, -83.379817],[33.939685, -83.385965],[33.958456, -83.378970],[33.960032, -83.382812],[33.958025, -83.378849]]
@IBOutlet weak var home: UIButton!
@IBOutlet weak var myMap: MKMapView!
var myLat = 33.958810
var myLong = -83.379817
override func viewDidLoad() {
super.viewDidLoad()
mainScrollView.contentSize.height = 2885
myMap.mapType = MKMapType.satellite
let initialLocation = CLLocation(latitude: myLat, longitude: myLong)
let regionRadius: CLLocationDistance = 1000
func centerMapOnLocation (location:CLLocation){
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius, regionRadius)
myMap.setRegion(coordinateRegion, animated: true)
}
centerMapOnLocation(location: initialLocation)
let howMany = latLong.count
var latLongCounter = 0
while (latLongCounter < howMany){
let pinLat = latLong [latLongCounter][0]
let pinLong = latLong [latLongCounter][1]
var pinCoordinates: CLLocationCoordinate2D = CLLocationCoordinate2D()
pinCoordinates.latitude = CDouble(pinLat)
pinCoordinates.longitude = CDouble(pinLong)
let pin: MKPointAnnotation = MKPointAnnotation()
pin.coordinate = pinCoordinates
self.myMap.addAnnotation(pin)
pin.title = myTitles[latLongCounter]
pin.subtitle = mySubtitles[latLongCounter]
latLongCounter += 1
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//if segue.identifier == "restaurants" {
//if let destination = segue.destination as? restaurants {
//destination.currentSite = self.currentSite
//}
//}
if segue.identifier == "button01" {
var url = NSURL(string: siteLink[0])
if let destination = segue.destination as? restaurants {
destination.url = self.url
}
//func loadPage(){
//var url = NSURL(string: siteLink[0])
//let url = NSURL(string: self.url)
//(string: siteLink[currentSite])
//let request = NSURLRequest(url:url as! URL)
//if let destination = segue.destination as? restaurants {
//destination.url = self.url
//}
//self.eatView.loadRequest(request as URLRequest)
//}
}
else if segue.identifier == "button02" {
var url = NSURL(string: siteLink[1])
if let destination = segue.destination as? restaurants {
destination.url = self.url
}
//func loadPage(){
//var url = NSURL(string: siteLink[1])
//let url = NSURL(string: self.url)
//(string: siteLink[currentSite])
//let request = NSURLRequest(url:url as! URL)
//if let destination = segue.destination as? restaurants {
//destination.url = self.url
//}
//self.eatView.loadRequest(request as URLRequest)
//}
}
else if segue.identifier == "button03" {
var url = NSURL(string: siteLink[2])
if let destination = segue.destination as? restaurants {
destination.url = self.url
}
//func loadPage(){
//var url = NSURL(string: siteLink[2])
//let url = NSURL(string: self.url)
//(string: siteLink[currentSite])
//let request = NSURLRequest(url:url as! URL)
//if let destination = segue.destination as? restaurants {
//destination.url = self.url
//}
//self.eatView.loadRequest(request as URLRequest)
//}
}
}
}
and View Controller 2 aka restaurants:
import UIKit
import MapKit
//var restaurantIndex = siteLink.count
//var urlWebsite = NSURL(string: siteLink[restaurantIndex])
//func displayURL ()
//{
//let myURLString = "http://google.com"
//let myURL = NSURL(string: myURLString)
//let myURLRequest = NSURLRequest(URL: myURL! asURL)
//webView.loadRequest(myURLRequest)
//}
class restaurants: UIViewController {
var siteLink = ["http://amici-cafe.com/athens.html", "http://www.athensbagel.com/", "https://www.facebook.com/dawggonegoodbbq/", "http://www.fuzzystacoshop.com/", "http://places.singleplatform.com/globe/menu?ref=google", "https://www.facebook.com/Kellys-Authentic-Jamaican-Food-333515583330794/", "http://theplaceathens.com/", "http://www.pauleyscrepebar.com/", "http://southkitchenbar.com/", "http://tazikiscafe.com/", "http://www.tedsmostbest.com/", "https://yourpie.com/", "http://trappezepub.com/", "http://www.vivaargentinecuisine.com/", "http://five-bar.com/bar-locations/athens-georgia/"]
var currentSite = 0
var url = String()
@IBOutlet weak var home: UIButton!
@IBOutlet weak var eatView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// displayURL ()
//func loadPage(){
let url = NSURL(string: self.url)
//(string: siteLink[currentSite])
let request = NSURLRequest(url:url as! URL)
self.eatView.loadRequest(request as URLRequest)
// }
//nermal
//let url = NSURL(string: "http://www.creaturecomfortsbeer.com/the-brand/")
//let request = NSURLRequest(url:url! as URL)
//self.webView!.loadRequest(request as URLRequest)
//jank
//let url = NSURL(string: siteLink[restaurantIndex])
//let request = NSURLRequest(url:url! as URL)
//self.webView!.loadRequest(request as URLRequest)
// }
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}