質問編集履歴
2
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,9 +9,8 @@
|
|
9
9
|
//構造体
|
10
10
|
let initialItems: [String] = []
|
11
11
|
var products: [[Cell]] = [[]]
|
12
|
-
|
13
|
-
|
14
12
|
var cnt = 0
|
13
|
+
//以下の2つの変数は削除予定
|
15
14
|
var item: [String] = []
|
16
15
|
var itemTotal: [[String]] = [[]]
|
17
16
|
|
1
現在のコードの更新、困っているの事についての具体的な説明
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,13 +8,16 @@
|
|
8
8
|
|
9
9
|
//構造体
|
10
10
|
let initialItems: [String] = []
|
11
|
-
var products: [Cell] = []
|
11
|
+
var products: [[Cell]] = [[]]
|
12
|
+
|
13
|
+
|
12
14
|
var cnt = 0
|
15
|
+
var item: [String] = []
|
13
16
|
var itemTotal: [[String]] = [[]]
|
14
17
|
|
15
18
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
16
19
|
if (products.count == 0
|
17
|
-
|| products.count > 0 &&
|
20
|
+
|| products.count > 0 && products[0].count == 0) {
|
18
21
|
return 0
|
19
22
|
} else {
|
20
23
|
return products.count
|
@@ -24,13 +27,13 @@
|
|
24
27
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
25
28
|
let cell = UITableViewCell()
|
26
29
|
|
27
|
-
let item1 = products[indexPath.row]
|
30
|
+
//let item1 = products[indexPath.row]
|
28
|
-
cell.textLabel?.text = item1.title
|
31
|
+
//cell.textLabel?.text = item1.title
|
29
32
|
|
30
33
|
let index = products.count - 1 - indexPath.row
|
31
|
-
let item = itemTotal[index]
|
34
|
+
let item = products[index]//itemTotal[index]
|
32
35
|
|
33
|
-
guard
|
36
|
+
guard item.count > 0 else {
|
34
37
|
return cell
|
35
38
|
}
|
36
39
|
|
@@ -40,7 +43,7 @@
|
|
40
43
|
for i in item {
|
41
44
|
let label = UILabel()
|
42
45
|
label.backgroundColor = UIColor.darkGray
|
43
|
-
label.text = i
|
46
|
+
label.text = i //string型じゃないとダメらしい 52行目 Cannot assign value of type 'Cell' to type 'String?'
|
44
47
|
|
45
48
|
|
46
49
|
// textLabel という名前の変数に格納された UILabel にフォントサイズの自動調整を設定します。
|
@@ -91,7 +94,7 @@
|
|
91
94
|
// アラートに含まれるすべてのテキストフィールドを調べる
|
92
95
|
for textField in textFields {
|
93
96
|
let name = textField.text!
|
94
|
-
self.products.insert(Cell(title: name, detail: name, cellcolor: false), at: 0)
|
97
|
+
self.products.insert([Cell(title: name, detail: name, cellcolor: false)], at: 0)
|
95
98
|
print(textField.text!)
|
96
99
|
}
|
97
100
|
self.mytableView.reloadData()
|
@@ -132,20 +135,20 @@
|
|
132
135
|
// アラートに含まれるすべてのテキストフィールドを調べる
|
133
136
|
for textField in textFields {
|
134
137
|
let name = textField.text!
|
135
|
-
self.products.append(Cell(detail: name, cellcolor: false ))
|
138
|
+
self.products.append([Cell(detail: name, cellcolor: false )])
|
136
|
-
|
139
|
+
self.item.insert(textField.text!, at: 0)
|
137
|
-
self.
|
140
|
+
self.products[self.cnt] = self.item //146行目 Cannot assign value of type '[String]' to type '[Cell]'
|
138
141
|
|
139
|
-
if self.item.count % 5 == 0, self.
|
142
|
+
if self.item.count % 5 == 0, self.products[0].count > 1 {
|
140
143
|
self.cnt += 1
|
141
|
-
self.
|
144
|
+
self.products.append([])
|
142
145
|
self.item = []
|
143
146
|
print(textField.text!)
|
144
147
|
//self.Gesture()
|
145
|
-
//self.doubleclic()
|
148
|
+
//self.doubleclic()
|
146
149
|
}
|
147
150
|
self.mytableView.reloadData()
|
148
|
-
|
151
|
+
}
|
149
152
|
}
|
150
153
|
})
|
151
154
|
alert.addAction(okAction)
|
@@ -202,8 +205,8 @@
|
|
202
205
|
mytableView.estimatedRowHeight = 60
|
203
206
|
mytableView.backgroundColor = UIColor(red: 0.0, green: 0.8, blue: 1.0, alpha: 0.1)
|
204
207
|
|
205
|
-
for detail in
|
208
|
+
for detail in item {
|
206
|
-
products.append(Cell(detail: detail, cellcolor: false))
|
209
|
+
products.append([Cell(detail: detail, cellcolor: false)])
|
207
210
|
}
|
208
211
|
mytableView.reloadData()
|
209
212
|
}
|
@@ -217,6 +220,7 @@
|
|
217
220
|
|
218
221
|
|
219
222
|
}
|
223
|
+
|
220
224
|
```
|
221
225
|
|
222
226
|
```swift
|
@@ -249,4 +253,6 @@
|
|
249
253
|
**困っていること**
|
250
254
|
コード的にはエラーはなく、実行しても落ちないのですがアラートで入力したものがセルに挿入されなくて困っている。
|
251
255
|
アラートはちゃんと呼び出せて入力したものがコンソールエリアに表示にされているのでアラートの処理の問題ではないと思われる。その為、cellForRowAt内に問題がると思われるが何が問題なのかが分からない。
|
252
|
-
題名となるセルはセクションでも良いではないかという指摘はあるかもしれないがスワイプ処理なども考え、今回はセル2行で出来るようにしたいと考えている。
|
256
|
+
題名となるセルはセクションでも良いではないかという指摘はあるかもしれないがスワイプ処理なども考え、今回はセル2行で出来るようにしたいと考えている。
|
257
|
+
52行目、146行目での構造体配列による型のエラーで困っています。
|
258
|
+
他には各箇所のitemをdetailにしたいが構造体の中にあるので書き換えれなく困っています。
|