前提・実現したいこと
ここに質問の内容を詳しく書いてください。
Xcodeで画像(写真)を表示するプログラムを書いていました。
しかし、エラーなしに実行はできたものの、画像を表示することができませんでした。
原因を知り、画像を表示できるようにしたいです。
発生している問題・エラーメッセージ
シミュレータ上で画像が表示されない。
Could not load the "画像のファイル名" image referenced from a nib in the bundle with identifier ""
該当のソースコード
Swift
1import UIKit 2class ViewController: UIViewController { 3 4 @IBOutlet weak var label: UILabel! 5 @IBOutlet weak var gazou: UIImageView! 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 self.title = "タイトル" 10 11 let image = UIImage(named: "ファイル名") 12 gazou.image = image 13 14 //labelの設定 15 label.text = "あいうえお" 16 label.numberOfLines = 0; 17 label.sizeToFit() 18 } 19 20 21 override func didReceiveMemoryWarning() { 22 super.didReceiveMemoryWarning() 23 // Dispose of any resources that can be recreated. 24 } 25 /* 26 // MARK: - Navigation 27 28 // In a storyboard-based application, you will often want to do a little preparation before navigation 29 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 30 // Get the new view controller using segue.destinationViewController. 31 // Pass the selected object to the new view controller. 32 } 33 */ 34 35} 36
補足情報(FW/ツールのバージョンなど)
プログラミング初心者の未熟なものですが宜しくお願い致します。
"... referenced from a nib ..." なので xib か storyboard上で設定された "画像のファイル名" というファイルが見つからないということです。そちらも確認しましょう。 (nibというのはxibやstoryboardをコンパイルすると生成されるUI用のデータファイルです)