作業9 — 只可遠觀不可褻玩焉的愛車賞析(array, 頁面間傳遞資料)
Published in
2 min readJun 27, 2017
讀取文件資料:array讀取是以“\n+空格”來做斷點
let url = Bundle.main.url(forResource: carTitle, withExtension: "txt")let content = try? String(contentsOf: url!)let array = content!.components(separatedBy: "\n ") //以換行+空白來區分
DetailLbn.text = array[0]
But! 比較要注意的是forResource, 因為他是以segue.id來搜尋文件的!
controller.carTitle = segue.identifier
照片顯示:是以carTitle相符名稱來顯示在Assets裡的照片
if carTitle == "911 GTS" {showCarView.image = UIImage(named:"911") //以標題來顯示對應的照片}else if carTitle == "Macan" {showCarView.image = UIImage(named:"macan")}else{showCarView.image = UIImage(named:"718")}