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 5 years have passed since last update.

メモ:Swiftでテーブルを作る時のお作法

Last updated at Posted at 2018-02-28

Swiftを勉強し始めたので自分用メモ。インデントの修正ははめんどくさいのでそのまま。

 table rowのサイズを宣言してあげる。

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return itemArray.count
    }
```

ellの値を決めてあげる

```
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoItemCell", for: indexPath)
        
        cell.textLabel?.text = itemArray[indexPath.row]
        return cell
    }
```

`tableView`はswiftのbuilt-in functionなのでoverrideが必用という認識。

選択したRowでイベントを発火させるとき。

```
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(itemArray[indexPath.row])
    }
```
tap gesture使ってた・・

選択したrowにアクセサリーで飾りをつけてあげる
`tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark`
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?