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

質問編集履歴

1

コードの変更

2018/04/03 05:39

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -6,15 +6,17 @@
6
6
 
7
7
  @IBOutlet weak var mytableView: UITableView!
8
8
  var add = UILabel()
9
- let item = ["kei"]
9
+ var item = [String]()
10
+
11
+
12
+ //+ボタン
10
13
  @IBAction func addlabel(_ sender: Any) {
11
-
12
14
  alert()
13
15
  }
14
16
 
15
17
  //ラベルについて
16
18
  func label(){
17
- add = UILabel (frame: CGRect())
19
+ add = UILabel(frame: CGRect(x: 130, y:250, width: 100, height:20))
18
20
  //ラベルの大きさ、座標指定
19
21
  //add.text = "labelです"
20
22
  //文字を変更
@@ -49,6 +51,8 @@
49
51
  // アラートに含まれるすべてのテキストフィールドを調べる
50
52
  for textField in textFields {
51
53
  self.label()
54
+ self.item.insert(textField.text!, at: 0)
55
+ self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
52
56
  self.add.text = textField.text!
53
57
  self.add.sizeToFit()
54
58
  print(textField.text!)
@@ -159,20 +163,25 @@
159
163
 
160
164
  }
161
165
 
166
+
167
+
162
168
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
163
169
  return item.count
164
170
  }
165
171
 
166
172
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
167
173
  let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
174
+ //cell.textLabel?.text = add.text
175
+ let todoLabel = item[indexPath.row]
168
- cell.textLabel?.text = add.text
176
+ cell.textLabel?.text = todoLabel
169
177
  return cell
170
178
  }
171
179
 
172
180
 
173
181
  override func viewDidLoad() {
174
182
  super.viewDidLoad()
175
-
183
+ mytableView.dataSource = self
184
+ mytableView.delegate = self
176
185
  }
177
186
 
178
187
 
@@ -185,6 +194,7 @@
185
194
 
186
195
  }
187
196
 
197
+
188
198
  ```
189
199
 
190
200
  **やりたいこと**