質問編集履歴
4
関数の引数について
test
CHANGED
File without changes
|
test
CHANGED
@@ -231,3 +231,97 @@
|
|
231
231
|
**エラーメッセージ**
|
232
232
|
|
233
233
|
Value of type 'ViewController' has no member 'label'
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
```swift
|
238
|
+
|
239
|
+
//アラート
|
240
|
+
|
241
|
+
func alert(n: String){
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
// OKボタンの設定
|
252
|
+
|
253
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
254
|
+
|
255
|
+
(action:UIAlertAction!) -> Void in
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
// OKを押した時入力されていたテキストを表示
|
260
|
+
|
261
|
+
if let textFields = alert.textFields {
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
266
|
+
|
267
|
+
for textField in textFields {
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
self.item.insert(textField.text!, at: 0)
|
272
|
+
|
273
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
274
|
+
|
275
|
+
label.text = textField.text!
|
276
|
+
|
277
|
+
print(textField.text!)
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
})
|
284
|
+
|
285
|
+
alert.addAction(okAction)
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
// キャンセルボタンの設定
|
290
|
+
|
291
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
292
|
+
|
293
|
+
alert.addAction(cancelAction)
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
// テキストフィールドを追加
|
298
|
+
|
299
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
300
|
+
|
301
|
+
textField.placeholder = "テキスト"
|
302
|
+
|
303
|
+
})
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
// アラートを画面に表示
|
312
|
+
|
313
|
+
self.present(alert, animated: true, completion: nil)
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
alert(n: "kei")
|
320
|
+
|
321
|
+
print(alert)
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
関数の引数について
|
3
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,206 +12,136 @@
|
|
12
12
|
|
13
13
|
var item = [String]()
|
14
14
|
|
15
|
+
|
16
|
+
|
17
|
+
@IBAction func addlabel(_ sender: Any) {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
alert()
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
30
|
+
|
31
|
+
return item.count
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
38
|
+
|
39
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
40
|
+
|
41
|
+
let todoLabel = item[indexPath.row]
|
42
|
+
|
43
|
+
cell.textLabel?.text = todoLabel
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
//ボタンについて
|
48
|
+
|
49
|
+
let button = UIButton()
|
50
|
+
|
51
|
+
button.backgroundColor = UIColor.blue
|
52
|
+
|
53
|
+
button.setTitle(" 追 加 ", for: .normal)
|
54
|
+
|
55
|
+
cell.contentView.addSubview(button)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
button.translatesAutoresizingMaskIntoConstraints = false
|
60
|
+
|
61
|
+
cell.contentView.rightAnchor.constraint(equalTo: button.rightAnchor, constant: 12).isActive = true
|
62
|
+
|
63
|
+
// 中央にする
|
64
|
+
|
65
|
+
//button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true
|
66
|
+
|
67
|
+
//丸みに対して
|
68
|
+
|
69
|
+
button.layer.cornerRadius = 10
|
70
|
+
|
71
|
+
button.layer.masksToBounds = true
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
cell.contentView.heightAnchor.constraint(equalTo: button.heightAnchor, multiplier: 1).isActive = true
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
//ラベルについて
|
80
|
+
|
81
|
+
var label = UILabel()
|
82
|
+
|
83
|
+
label.backgroundColor = UIColor.darkGray
|
84
|
+
|
85
|
+
label.text = "120×10"
|
86
|
+
|
87
|
+
//丸みに対して
|
88
|
+
|
89
|
+
label.layer.cornerRadius = 5
|
90
|
+
|
91
|
+
label.layer.masksToBounds = true
|
92
|
+
|
93
|
+
cell.contentView.addSubview(label)
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
label.translatesAutoresizingMaskIntoConstraints = false
|
98
|
+
|
99
|
+
cell.contentView.leftAnchor.constraint(equalTo: label.leftAnchor, constant: -6).isActive = true
|
100
|
+
|
101
|
+
cell.contentView.heightAnchor.constraint(equalTo: label.heightAnchor, multiplier: 1).isActive = true
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
//アラート
|
106
|
+
|
15
|
-
func alert(){
|
107
|
+
func alert(){
|
16
|
-
|
17
|
-
|
108
|
+
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
109
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
22
|
-
|
23
|
-
|
24
|
-
|
110
|
+
|
111
|
+
|
112
|
+
|
25
|
-
// OKボタンの設定
|
113
|
+
// OKボタンの設定
|
26
|
-
|
114
|
+
|
27
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
115
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
28
|
-
|
116
|
+
|
29
|
-
(action:UIAlertAction!) -> Void in
|
117
|
+
(action:UIAlertAction!) -> Void in
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// OKを押した時入力されていたテキストを表示
|
34
|
-
|
35
|
-
if let textFields = alert.textFields {
|
36
118
|
|
37
119
|
|
38
120
|
|
121
|
+
// OKを押した時入力されていたテキストを表示
|
122
|
+
|
123
|
+
if let textFields = alert.textFields {
|
124
|
+
|
125
|
+
|
126
|
+
|
39
|
-
// アラートに含まれるすべてのテキストフィールドを調べる
|
127
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
40
|
-
|
128
|
+
|
41
|
-
for textField in textFields {
|
129
|
+
for textField in textFields {
|
42
|
-
|
43
|
-
|
130
|
+
|
44
|
-
|
131
|
+
|
132
|
+
|
45
|
-
self.item.insert(textField.text!, at: 0)
|
133
|
+
self.item.insert(textField.text!, at: 0)
|
134
|
+
|
46
|
-
|
135
|
+
self.label.text = textField.text!
|
136
|
+
|
47
|
-
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
137
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
48
|
-
|
138
|
+
|
49
|
-
print(textField.text!)
|
139
|
+
print(textField.text!)
|
50
|
-
|
140
|
+
|
51
|
-
|
141
|
+
}
|
52
|
-
|
53
|
-
self.doubleclic()
|
54
142
|
|
55
143
|
}
|
56
144
|
|
57
|
-
}
|
58
|
-
|
59
|
-
})
|
60
|
-
|
61
|
-
alert.addAction(okAction)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
// キャンセルボタンの設定
|
66
|
-
|
67
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
68
|
-
|
69
|
-
alert.addAction(cancelAction)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
// テキストフィールドを追加
|
74
|
-
|
75
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
76
|
-
|
77
|
-
textField.placeholder = "テキスト"
|
78
|
-
|
79
|
-
})
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
// アラートを画面に表示
|
88
|
-
|
89
|
-
self.present(alert, animated: true, completion: nil)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
100
|
-
|
101
|
-
return item.count
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
108
|
-
|
109
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
110
|
-
|
111
|
-
let todoLabel = item[indexPath.row]
|
112
|
-
|
113
|
-
cell.textLabel?.text = todoLabel
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
//ボタンについて
|
118
|
-
|
119
|
-
let button = UIButton()
|
120
|
-
|
121
|
-
button.backgroundColor = UIColor.blue
|
122
|
-
|
123
|
-
button.setTitle(" 追 加 ", for: .normal)
|
124
|
-
|
125
|
-
cell.contentView.addSubview(button)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
button.translatesAutoresizingMaskIntoConstraints = false
|
130
|
-
|
131
|
-
cell.contentView.rightAnchor.constraint(equalTo: button.rightAnchor, constant: 12).isActive = true
|
132
|
-
|
133
|
-
// 中央にする
|
134
|
-
|
135
|
-
//button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true
|
136
|
-
|
137
|
-
//丸みに対して
|
138
|
-
|
139
|
-
button.layer.cornerRadius = 10
|
140
|
-
|
141
|
-
button.layer.masksToBounds = true
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
cell.contentView.heightAnchor.constraint(equalTo: button.heightAnchor, multiplier: 1).isActive = true
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
//ラベルについて
|
150
|
-
|
151
|
-
var label = UILabel()
|
152
|
-
|
153
|
-
label.backgroundColor = UIColor.darkGray
|
154
|
-
|
155
|
-
label.text = "120×10"
|
156
|
-
|
157
|
-
//丸みに対して
|
158
|
-
|
159
|
-
label.layer.cornerRadius = 5
|
160
|
-
|
161
|
-
label.layer.masksToBounds = true
|
162
|
-
|
163
|
-
cell.contentView.addSubview(label)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
label.translatesAutoresizingMaskIntoConstraints = false
|
168
|
-
|
169
|
-
cell.contentView.leftAnchor.constraint(equalTo: label.leftAnchor, constant: -6).isActive = true
|
170
|
-
|
171
|
-
cell.contentView.heightAnchor.constraint(equalTo: label.heightAnchor, multiplier: 1).isActive = true
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
//アラート
|
176
|
-
|
177
|
-
func alert(){
|
178
|
-
|
179
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
// OKボタンの設定
|
184
|
-
|
185
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
186
|
-
|
187
|
-
(action:UIAlertAction!) -> Void in
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
// OKを押した時入力されていたテキストを表示
|
192
|
-
|
193
|
-
if let textFields = alert.textFields {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// アラートに含まれるすべてのテキストフィールドを調べる
|
198
|
-
|
199
|
-
for textField in textFields {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
self.item.insert(textField.text!, at: 0)
|
204
|
-
|
205
|
-
self.label.text = textField.text!
|
206
|
-
|
207
|
-
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
208
|
-
|
209
|
-
print(textField.text!)
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
145
|
})
|
216
146
|
|
217
147
|
alert.addAction(okAction)
|
2
エラーメッセージ
test
CHANGED
File without changes
|
test
CHANGED
@@ -297,3 +297,7 @@
|
|
297
297
|
self.label.text = textField.text!の部分でlabelの部分でエラーが起きていてどう書いてもエラーが取れなくて困っています。
|
298
298
|
|
299
299
|
試しにcellForRowAt外にlabelのインスタンスを作ると外のインスタンスに対してはエラーが起きませんでした。
|
300
|
+
|
301
|
+
**エラーメッセージ**
|
302
|
+
|
303
|
+
Value of type 'ViewController' has no member 'label'
|
1
こーどの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
```swift
|
2
2
|
|
3
|
-
//
|
4
|
-
|
5
|
-
// ViewController.swift
|
6
|
-
|
7
|
-
// btr-label
|
8
|
-
|
9
|
-
//
|
10
|
-
|
11
|
-
// Created by 西川継延 on 2018/02/25.
|
12
|
-
|
13
|
-
// Copyright © 2018年 西川継延. All rights reserved.
|
14
|
-
|
15
|
-
//
|
16
|
-
|
17
|
-
|
18
|
-
|
19
3
|
import UIKit
|
20
4
|
|
21
5
|
|