FromNowOn2017 / SWIFT

SWIFTのサンプルの投稿
0 stars 0 forks source link

CustomCell #11

Open FromNowOn2017 opened 6 years ago

FromNowOn2017 commented 6 years ago

ViewController.swift

// sampleCustomCell // // Created by togashi yoshiki on 2017/06/29. // Copyright © 2017年 Yoshiki Togashi. All rights reserved. //

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { // let image1 = UIImage(named: "1.png") // let image2 = UIImage(named: "2.png")

/// 画像のファイル名
let imageNames = ["1.png", "2.png", "3.png", "4.png"]

/// 画像のタイトル
let imageTitles = ["プレミアム", "イラレ", "フォトショ", "ドリバー"]

/// 画像の説明
let imageDescriptions = [
    "動画の編集に使います",
    "アイコンの作成などに使います。",
    "写真編集に使います。",
    "HP作成に作成します。"
]

/// セルの個数を指定するデリゲートメソッド(必須)
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return imageNames.count
}

/// セルに値を設定するデータソースメソッド(必須)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // セルを取得
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomTableViewCell
    // セルに値を設定
    cell.myImageView.image = UIImage(named: imageNames[indexPath.row])
    cell.myTitleLabel.text = imageTitles[indexPath.row]
    cell.myDescriptionLabel.text = imageDescriptions[indexPath.row]
    return cell
}

// 初期設定 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}