。
tableviewを表示したい
Swiftでtableviewを表示させたいのですが、どうしてもうまくいかないので見てもらいたいです。
エラーとかは何も出ていないのですが、ビルドしたとき何も画面に映らないです。
コード
ViewController
ViewController
1import UIKit 2 3class ViewController : UIViewController,UITableViewDelegate,UITableViewDataSource{ 4 5 @IBOutlet weak var TableView: UITableView! 6 7 /// 画像のファイル名 8 let imageNames = ["バルセロナ.jpg", "ナポリ.jpg", "リアルマドリード.jpg", "ガンバ大阪.jpg"] 9 10 /// 画像のタイトル 11 let imageTitles = ["バルセロナ", "ナポリ", "リアルマドリード", "ガンバ大阪"] 12 13 /// 画像の説明 14 let imageDescriptions = [ 15 "ああああああああああああ", 16 "ああああああああああああ", 17 "ああああああああああああ", 18 "ああああああああああああ" 19 ] 20 21 22 override func viewDidLoad() { 23 super.viewDidLoad() 24 // Do any additional setup after loading the view, typically from a nib. 25 } 26 override func didReceiveMemoryWarning() { 27 super.didReceiveMemoryWarning() 28 // Dispose of any resources that can be recreated. 29 } 30 31 /// セルの個数を指定するデリゲートメソッド(必須) 32 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 33 return imageNames.count 34 } 35 36 /// セルに値を設定するデータソースメソッド(必須) 37 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 38 //? 39 let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell",for: indexPath) as! CustomCell 40 41 // セルに値を設定 42 cell.soccer_image.image = UIImage(named: imageNames[indexPath.row]) 43 cell.teame_name.text = imageTitles[indexPath.row] 44 cell.reaage.text = imageDescriptions[indexPath.row] 45 46 return cell 47 } 48} 49
CustomCell
CustomCell
1import UIKit 2 3class CustomCell: UITableViewCell { 4 5 @IBOutlet weak var soccer_image: UIImageView! 6 @IBOutlet weak var teame_name: UILabel! 7 @IBOutlet weak var reaage: UILabel! 8 9 override func awakeFromNib() { 10 super.awakeFromNib() 11 // Initialization code 12 }
試したこと
classの指定、identifierの指定も行なっています。
画面になぜ表示されないのか、色々調べたのですが全部行なっていると思うので原因がわかりませんでした。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/30 05:03