質問するログイン新規登録

質問編集履歴

3

tableViewの情報を追加

2017/01/24 12:34

投稿

KazutakaShimizu
KazutakaShimizu

スコア157

title CHANGED
File without changes
body CHANGED
@@ -3,12 +3,41 @@
3
3
 
4
4
  tableViewの設定は下記です。
5
5
  ```swift
6
+ import UIKit
7
+
8
+ class ViewController: UIViewController {
9
+ @IBOutlet var tableView: UITableView!
10
+ var datas = [true, false, true, false, false]
11
+
12
+ override func viewDidLoad() {
13
+ super.viewDidLoad()
6
14
  tableView.delegate = self
7
15
  tableView.dataSource = self
8
16
  let nib = UINib(nibName: "TableViewCell", bundle: nil)
9
17
  tableView.register(nib, forCellReuseIdentifier: "Cell")
10
18
  tableView.estimatedRowHeight = 350
11
19
  tableView.rowHeight = UITableViewAutomaticDimension
20
+
21
+ }
22
+
23
+ private func createData() -> [Bool]{
24
+ let datas = [true, false, true, false, false]
25
+ return datas
26
+ }
27
+ }
28
+
29
+ extension ViewController: UITableViewDelegate, UITableViewDataSource {
30
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
31
+ return datas.count
32
+ }
33
+
34
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
35
+ var cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
36
+ print(datas[indexPath.row])
37
+ cell.data = datas[indexPath.row]
38
+ return cell
39
+ }
40
+ }
12
41
  ```
13
42
  セル内でのautolayoutの設定は下記です.
14
43
 

2

setUpUIの呼び出し元を追加

2017/01/24 12:33

投稿

KazutakaShimizu
KazutakaShimizu

スコア157

title CHANGED
File without changes
body CHANGED
@@ -13,6 +13,13 @@
13
13
  セル内でのautolayoutの設定は下記です.
14
14
 
15
15
  ```swift
16
+ var data: Bool? {
17
+ didSet{
18
+ guard let data = data else { return }
19
+ self.setUpUI(data: data)
20
+ }
21
+ }
22
+
16
23
  private func setUpUI(data:Bool){
17
24
  if data == true {
18
25
  label.backgroundColor = .blue

1

制約の部分が間違っていたので修正しました

2017/01/24 04:02

投稿

KazutakaShimizu
KazutakaShimizu

スコア157

title CHANGED
File without changes
body CHANGED
@@ -19,16 +19,12 @@
19
19
  label.snp.makeConstraints({ (make) -> Void in
20
20
  make.top.equalTo(10)
21
21
  make.bottom.equalTo(10)
22
- make.left.equalTo(10)
23
- make.right.equalTo(10)
24
22
  })
25
23
  }else{
26
24
  label.backgroundColor = .red
27
25
  label.snp.makeConstraints({ (make) -> Void in
28
26
  make.top.equalTo(100)
29
27
  make.bottom.equalTo(100)
30
- make.left.equalTo(100)
31
- make.right.equalTo(100)
32
28
  })
33
29
  }
34
30
  }