###Segueでのデータ受け渡しができない
こんにちは。いつもお世話になってます。
ViewController間でデータの受け渡しをしたいのですが、上手くいかないです。
######試したこと
http://swift-ios.keicode.com/ios/passing-values-between-views.php
このサイトに書いてあることがほぼ僕のやりたいことと同じなのですが、違うのは僕のやりたいことは関数にStringを受け渡すことです。イマイチ何を間違っているのかわからず。。。
わかる方おられましたらお力をお貸しください。宜しくお願いします。
######ViewController1(ArtViewController)
Swift
1 2import UIKit 3 4class ArtViewController: UIViewController { 5 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 // Do any additional setup after loading the view. 11 } 12 13 override func didReceiveMemoryWarning() { 14 super.didReceiveMemoryWarning() 15 // Dispose of any resources that can be recreated. 16 } 17 18 19 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 20 var webViewController: WebViewController = segue.destination as! WebViewController 21 22 if segue.identifier == "art1"{ 23 webViewController.receiveURL = "http://google.com" 24 } 25 } 26 27} 28
######ViewController2(WebViewController)
Swift
1import UIKit 2 3 4class WebViewController: UIViewController { 5 6 7 @IBOutlet var webView: UIWebView! 8 var receiveURL:String? 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 loadURL(url: receiveURL!) 12 13 14 // Do any additional setup after loading the view. 15 } 16 17 override func didReceiveMemoryWarning() { 18 super.didReceiveMemoryWarning() 19 // Dispose of any resources that can be recreated. 20 } 21 22 func loadURL(url: String){ 23 let requestURL = NSURL(string: url) 24 let request = NSURLRequest(url:requestURL! as URL) 25 webView.loadRequest(request as URLRequest) 26 } 27}