セルのスタイルについてちょっと書いてみる。
UITableViewCellを作るときにstyleに設定する値で変わる。
// 内容を返す。
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
cell.textLabel?.text = "cell-\(indexPath.row)"
cell.detailTextLabel?.text = "detail"
return cell
}
このプログラムのstyleの部分をかえてやってみた。
.default

.value1

.value2

.subtitle

けっこー、いろんな表示ができる。
セルに画像もつけれるので、イメージを用意して次のコードを追加する。
cell.imageView?.image = UIImage(named: "image@2x.png")

accessoryTypeを指定すると右側にアクセサリ(と言うのかな?)が付く。
cell.accessoryType = UITableViewCellAccessoryType.none
UITableViewCellAccessoryType.none

UITableViewCellAccessoryType.disclosureIndicator

UITableViewCellAccessoryType.detailDisclosureButton

UITableViewCellAccessoryType.checkmark

UITableViewCellAccessoryType.detailButton

コメント