UITableVeiw Practice -1

박인준·2019년 12월 17일
0

Swift

목록 보기
18/21

1부터 50까지의 숫자 출력하기

import UIKit

final class TableViewNumbers: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    
    let tableView = UITableView(frame: view.frame)
    tableView.dataSource = self
    view.addSubview(tableView)
  }
}

extension TableViewNumbers: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: UITableViewCell
        if let reusableCell = tableView.dequeueReusableCell(withIdentifier: "CellId") {
            cell = reusableCell
        } else {
            cell = UITableViewCell(style: .default, reuseIdentifier: "CellId")
        }
        cell.textLabel?.text = "\((indexPath.row)+1)"
        return cell
    }
   
}

profile
iOS 개발자가 되기 위해

0개의 댓글