9
8

More than 5 years have passed since last update.

Swift3でテーブルに「>」(右向き矢印)のアイコンをつける

Last updated at Posted at 2017-04-04

Swift3でテーブルに「>」(右向き矢印)のアイコンをつける

今回の目標

テーブルのセルに「>」のアクセサリを表示する

Qiita用Cells.png

開発環境

  • Xcode:8.2.1
  • 言語:Swift 3
  • OS:MacOS

アイコン表示方法

Storyboardで事前にTableViewを作成し、CellにIdentifier(今回は"Cells")を付与しておきます
そのCellを指定する形で下記のコードを実装します
UITableviewCell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator

サンプルコード

ViewController.swift
    let display:Array = ["cell1", "cell2", "cell3"]

    // Cellの値を設定
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath) // Storyboard上のテーブルセルのIdentifierと一致
        cell.textLabel!.text = display[indexPath.row]
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator // ここで「>」ボタンを設定
        return cell
    }

備考

UITableViewCellAccessoryType.disclosureIndicatorを指定する時にdisclosureIndicator以外の種類として、チェックマーク(checkmark)や詳細(インフォメーション)マーク(detailButton)なども設定できる

9
8
2

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
9
8