0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TableView Cellにチェックマークなどを表示する(.accessoryType) 

Posted at

今回の内容

  • .accessoryTypeを用いてTableViewのCellにチェックマークなどを表示する。

コードと簡単解説

.accessoryType = .checkmark

66E4123C-F50A-4094-9B3C-81AA0814D914_1_105_c.jpeg
  • func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {}内でindexPathからタップされたCellを取得します。

  • cell?.accessoryType = .checkmark でタップされたCellにチェックマークを表示します。

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell = tableView.cellForRow(at: indexPath)
        
        cell?.accessoryType = .checkmark  //チェックマーク
     
    }

.accessoryType = .detailButton

E6B9FC7F-EB38-4242-9B4F-72648226CECE_1_105_c.jpeg
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell = tableView.cellForRow(at: indexPath)
        
        cell?.accessoryType = .detailButton
     
    }

.accessoryType = .disclosureIndicator

A3897341-6011-4620-BB74-7B2F89519024_1_105_c.jpeg
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell = tableView.cellForRow(at: indexPath)
        
        cell?.accessoryType = .disclosureIndicator
     
    }

.accessoryType = .detailDisclosureButton

300CFDAD-0DC6-4D1C-A3FF-83FE3C46EE1D_1_105_c.jpeg
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell = tableView.cellForRow(at: indexPath)
        
        cell?.accessoryType = .detailDisclosureButton
     
    }

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?