swift tableview custom 스위프트 테이블뷰 커스텀
//
// MainViewController.swift
// TableViewAI
//
// Created by stayfoolish on 20/11/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class MainViewController: UIViewController, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
let sampleData = SampleData()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.tableView.dataSource = self
self.tableView.tableFooterView = UIView(frame: .zero)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.sampleData.samples.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "mainFeatureCell", for: indexPath) as! MainFeatureCell
let sample = self.sampleData.samples[indexPath.row]
cell.titleLabel.text = sample.title
cell.descriptionLabel.text = sample.description
cell.imageView?.image = UIImage(named: sample.image)
return cell
}
}
//
// SampleData.swift
// TableViewAI
//
// Created by stayfoolish on 20/11/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import Foundation
struct Sample {
let title: String
let description: String
let image: String
}
struct SampleData {
let samples = [
Sample(title: "Photo Object Detection", description: "불러온 이미지에 사물 인식", image: "ic_photo"),
Sample(title: "Real Time Object Detection", description: "실시간으로 카메라에 보이는 사물 인식", image: "ic_camera"),
Sample(title: "Facial Analysis", description: "사람 얼굴로부터 나이, 성별, 감정 추측", image: "ic_emotion")
]
}
//
// MainFeatureCell.swift
// TableViewAI
//
// Created by stayfoolish on 20/11/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class MainFeatureCell: UITableViewCell {
@IBOutlet var featureImageView: UIImageView!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var descriptionLabel: UILabel!
}
'Swift > 기초&문법' 카테고리의 다른 글
swift alertcontroller 스위프트 얼럿컨트롤러 (0) | 2018.11.14 |
---|---|
swift tableview didselectrowat 스위프트 테이블뷰 선택하였을 때 (0) | 2018.11.13 |
swift tableview array 스위프트 테이블뷰 (0) | 2018.11.11 |
swift tableview 간단한 스위프트 테이블뷰 , 디테일 뷰 (0) | 2018.11.10 |
swift tableview 간단한 테이블뷰 추가, 삭제 스위프트 (0) | 2018.11.08 |