LoginSignup
0
0

More than 5 years have passed since last update.

UITableview

オートレイアウトでtableViewを画面いっぱいに表示

let tableView: UITableView = UITableView()
tableView.dataSource = self

        tableView.register(InformationTopCell.self, forCellReuseIdentifier: 
        "InformationTopCell")

        // オートレイアウト時にUIViewのレイアウトが変更しないようにする
        tableView.translatesAutoresizingMaskIntoConstraints = false

        // カスタマイズビューを追加
        view.addSubview(tableView)

        // オートレイアウトでtableViewを画面いっぱいに表示
        tableView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

        //仮の値(小さいと成約がでるためある程度余裕を持つ)
        tableView.estimatedRowHeight = 1000
        tableView.rowHeight = UITableViewAutomaticDimension

tableViewを使う時、多くの場合カスタムセルクラスを作ってtableViewにregisterしてからdequeueする、という決まった手順を踏むことになる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0