Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?


More than 3 years have passed since last update.


1. Storyboardでヘッダーとフッター用のUITableViewCellを用意

スクリーンショット 2017-03-20 20.23.49.png

2. ViewControllerのviewDidLoadでTableViewのヘッダーとフッターを設定


class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.

        tableView.dataSource = self
        tableView.delegate = self

        // TableViewのヘッダーを設定
        let headerCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "tableHeaderCell")!
        let headerView: UIView = headerCell.contentView
        tableView.tableHeaderView = headerView

        // TableViewのフッターを設定
        let footerCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "tableFooterCell")!
        let footerView: UIView = footerCell.contentView
        tableView.tableFooterView = footerView

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

    // 行数
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "articleCell")!
        return cell

    // セクション数
    public func numberOfSections(in tableView: UITableView) -> Int {
        return 1

    // セクションヘッダーの高さ
    public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 50
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away