質問編集履歴
3
コードの追加と写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -332,22 +332,36 @@
|
|
332
332
|
|
333
333
|
@IBAction func ok(_ sender: Any) {
|
334
334
|
|
335
|
+
let name1 = lepstxt.text
|
336
|
+
|
337
|
+
//let name2 = lepspicker.textInputMode
|
338
|
+
|
335
|
-
let name
|
339
|
+
let name3 = "個"
|
336
|
-
|
340
|
+
|
337
|
-
let name
|
341
|
+
let name4 = "×"
|
342
|
+
|
343
|
+
let name5 = kgtxt.text
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
338
348
|
|
339
349
|
lepstxt.text = String()
|
340
350
|
|
341
351
|
kgtxt.text = String()
|
342
352
|
|
343
|
-
|
344
|
-
|
345
|
-
print(
|
353
|
+
print(name1! + name3 + name4 + name5!)
|
346
354
|
|
347
355
|
let str = "print"
|
348
356
|
|
349
357
|
delegate?.appendData(str: str) // ViewControllerのメソッドを実行
|
350
358
|
|
359
|
+
self.removeFromSuperview()
|
360
|
+
|
351
361
|
}
|
352
362
|
|
353
363
|
```
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+

|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -325,3 +325,29 @@
|
|
325
325
|
のように表示させたい。
|
326
326
|
|
327
327
|
()がlabel []がsegment 後はtextfieldです
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
```swift
|
332
|
+
|
333
|
+
@IBAction func ok(_ sender: Any) {
|
334
|
+
|
335
|
+
let name1 = "個"
|
336
|
+
|
337
|
+
let name2 = "×"
|
338
|
+
|
339
|
+
lepstxt.text = String()
|
340
|
+
|
341
|
+
kgtxt.text = String()
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
print(String(describing: lepstxt) + item + name1 + name2 + String(describing: kgtxt) + kglbs)
|
346
|
+
|
347
|
+
let str = "print"
|
348
|
+
|
349
|
+
delegate?.appendData(str: str) // ViewControllerのメソッドを実行
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
```
|
1
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,12 +20,6 @@
|
|
20
20
|
|
21
21
|
@IBAction func customalertbtr(_ sender: Any) {
|
22
22
|
|
23
|
-
/*let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 300 , height: 200))
|
24
|
-
|
25
|
-
view.backgroundColor = .orange
|
26
|
-
|
27
|
-
self.view.addSubview(view)*/
|
28
|
-
|
29
23
|
let customAlert = CustomAlert(frame: CGRect(x: 0.0, y: 0.0, width: 350 , height: 275))
|
30
24
|
|
31
25
|
customAlert.center = self.view.center
|
@@ -38,69 +32,229 @@
|
|
38
32
|
|
39
33
|
}
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
a
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
35
|
+
|
36
|
+
|
37
|
+
override func viewDidLoad() {
|
38
|
+
|
39
|
+
super.viewDidLoad()
|
40
|
+
|
41
|
+
// Do any additional setup after loading the view, typically from a nib.
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
override func didReceiveMemoryWarning() {
|
48
|
+
|
49
|
+
super.didReceiveMemoryWarning()
|
50
|
+
|
51
|
+
// Dispose of any resources that can be recreated.
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
CustomAlert.swift
|
66
|
+
|
67
|
+
```swift
|
68
|
+
|
69
|
+
import UIKit
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
class CustomAlert: UIView ,UIPickerViewDataSource,UIPickerViewDelegate {
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
//lepsに関して
|
78
|
+
|
79
|
+
let item = ["-5","-4","-3","-2","-1","0","1","2","3","4","5",]
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
@IBOutlet var myview: UIView!
|
84
|
+
|
85
|
+
@IBOutlet weak var titlelbl: UILabel!
|
86
|
+
|
87
|
+
@IBOutlet weak var exlbl: UILabel!
|
88
|
+
|
89
|
+
@IBOutlet weak var lepstxt: UITextField!
|
90
|
+
|
91
|
+
@IBOutlet weak var kgtxt: UITextField!
|
92
|
+
|
93
|
+
@IBOutlet weak var lepslbl: UILabel!
|
94
|
+
|
95
|
+
@IBOutlet weak var lepspicker: UIPickerView!
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
@IBAction func kglbs(_ sender: Any)
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
switch (sender as AnyObject).selectedSegmentIndex {
|
104
|
+
|
105
|
+
case 0:
|
106
|
+
|
107
|
+
//mytableView.text = "kg"
|
108
|
+
|
109
|
+
print("kg")
|
110
|
+
|
111
|
+
case 1:
|
112
|
+
|
113
|
+
//mytableView.text = "lbs"
|
114
|
+
|
115
|
+
print("lbs")
|
116
|
+
|
117
|
+
default: break
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
@IBAction func difficulty(_ sender: Any)
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
switch (sender as AnyObject).selectedSegmentIndex {
|
130
|
+
|
131
|
+
case 0:
|
132
|
+
|
133
|
+
kgtxt.textColor = UIColor.blue
|
134
|
+
|
135
|
+
case 1:
|
136
|
+
|
137
|
+
kgtxt.textColor = UIColor.red
|
138
|
+
|
139
|
+
case 3:
|
140
|
+
|
141
|
+
kgtxt.textColor = UIColor.darkGray
|
142
|
+
|
143
|
+
default: break
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//コードから
|
158
|
+
|
159
|
+
override init(frame: CGRect) {
|
160
|
+
|
161
|
+
super.init(frame: frame)
|
162
|
+
|
163
|
+
self.commonInit()
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//ストボーから
|
170
|
+
|
171
|
+
required init?(coder aDecoder: NSCoder) {
|
172
|
+
|
173
|
+
super.init(coder: aDecoder)
|
174
|
+
|
175
|
+
self.commonInit()
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
fileprivate func commonInit() {
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
guard let view = UINib(nibName: "CustomAlert", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else {
|
186
|
+
|
187
|
+
return
|
66
188
|
|
67
189
|
}
|
68
190
|
|
191
|
+
|
192
|
+
|
193
|
+
//textfieldに関して
|
194
|
+
|
195
|
+
lepstxt.placeholder = "個数を入力してください。"
|
196
|
+
|
197
|
+
kgtxt.placeholder = "値段を入力してください。"
|
198
|
+
|
69
|
-
let
|
199
|
+
lepstxt.font = UIFont(name: "Hiragino Sans", size: 11)
|
200
|
+
|
70
|
-
|
201
|
+
kgtxt.font = UIFont(name: "Hiragino Sans", size: 11)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
//デリゲート設定
|
206
|
+
|
207
|
+
lepspicker.delegate = self
|
208
|
+
|
209
|
+
lepspicker.dataSource = self
|
210
|
+
|
211
|
+
//lepspicker.selectedRow(inComponent: 6)
|
212
|
+
|
213
|
+
//lepspicker.backgroundColor = .gray
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
view.frame = self.bounds
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
self.addSubview(view)
|
222
|
+
|
223
|
+
|
224
|
+
|
71
|
-
|
225
|
+
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
226
|
+
|
76
|
-
|
77
|
-
|
227
|
+
|
78
|
-
|
79
|
-
|
228
|
+
|
80
|
-
|
81
|
-
|
229
|
+
@IBAction func cancel(_ sender: Any) {
|
82
|
-
|
83
|
-
|
230
|
+
|
84
|
-
|
85
|
-
|
231
|
+
self.removeFromSuperview()
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
232
|
+
|
90
|
-
|
91
|
-
alert.addAction(cancelAction)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
present(alert, animated: true, completion: nil)
|
96
|
-
|
97
|
-
}
|
233
|
+
}
|
234
|
+
|
235
|
+
@IBAction func ok(_ sender: Any) {
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
let item = lepstxt.text
|
240
|
+
|
241
|
+
let array = kgtxt.text
|
242
|
+
|
243
|
+
lepslbl.text = String()
|
244
|
+
|
245
|
+
//mytbleView.text = String(item,array)
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
98
252
|
|
99
253
|
// PickerViewの列数
|
100
254
|
|
101
255
|
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
102
256
|
|
103
|
-
return
|
257
|
+
return 1
|
104
258
|
|
105
259
|
}
|
106
260
|
|
@@ -110,15 +264,7 @@
|
|
110
264
|
|
111
265
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
112
266
|
|
113
|
-
if component == 0 {
|
114
|
-
|
115
|
-
// 1個目のピッカーの設定
|
116
|
-
|
117
|
-
|
267
|
+
return item.count
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
return datalist2.count
|
122
268
|
|
123
269
|
}
|
124
270
|
|
@@ -128,13 +274,7 @@
|
|
128
274
|
|
129
275
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
130
276
|
|
131
|
-
if component == 0 {
|
132
|
-
|
133
|
-
|
277
|
+
return item[row]
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
return datalist2[row]
|
138
278
|
|
139
279
|
}
|
140
280
|
|
@@ -152,268 +292,10 @@
|
|
152
292
|
|
153
293
|
|
154
294
|
|
155
|
-
override func viewDidLoad() {
|
156
|
-
|
157
|
-
super.viewDidLoad()
|
158
|
-
|
159
|
-
// Do any additional setup after loading the view, typically from a nib.
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
override func didReceiveMemoryWarning() {
|
166
|
-
|
167
|
-
super.didReceiveMemoryWarning()
|
168
|
-
|
169
|
-
// Dispose of any resources that can be recreated.
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
295
|
}
|
178
296
|
|
179
|
-
|
180
|
-
|
181
297
|
```
|
182
298
|
|
183
|
-
CustomAlert.swift
|
184
|
-
|
185
|
-
```swift
|
186
|
-
|
187
|
-
import UIKit
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
class CustomAlert: UIView ,UIPickerViewDataSource,UIPickerViewDelegate {
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
//lepsに関して
|
196
|
-
|
197
|
-
let item = ["-5","-4","-3","-2","-1","0","1","2","3","4","5",]
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
@IBOutlet var myview: UIView!
|
202
|
-
|
203
|
-
@IBOutlet weak var titlelbl: UILabel!
|
204
|
-
|
205
|
-
@IBOutlet weak var exlbl: UILabel!
|
206
|
-
|
207
|
-
@IBOutlet weak var lepstxt: UITextField!
|
208
|
-
|
209
|
-
@IBOutlet weak var kgtxt: UITextField!
|
210
|
-
|
211
|
-
@IBOutlet weak var lepslbl: UILabel!
|
212
|
-
|
213
|
-
@IBOutlet weak var lepspicker: UIPickerView!
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
@IBAction func kglbs(_ sender: Any)
|
218
|
-
|
219
|
-
{
|
220
|
-
|
221
|
-
switch (sender as AnyObject).selectedSegmentIndex {
|
222
|
-
|
223
|
-
case 0:
|
224
|
-
|
225
|
-
//mytableView.text = "kg"
|
226
|
-
|
227
|
-
print("kg")
|
228
|
-
|
229
|
-
case 1:
|
230
|
-
|
231
|
-
//mytableView.text = "lbs"
|
232
|
-
|
233
|
-
print("lbs")
|
234
|
-
|
235
|
-
default: break
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
@IBAction func difficulty(_ sender: Any)
|
244
|
-
|
245
|
-
{
|
246
|
-
|
247
|
-
switch (sender as AnyObject).selectedSegmentIndex {
|
248
|
-
|
249
|
-
case 0:
|
250
|
-
|
251
|
-
kgtxt.textColor = UIColor.blue
|
252
|
-
|
253
|
-
case 1:
|
254
|
-
|
255
|
-
kgtxt.textColor = UIColor.red
|
256
|
-
|
257
|
-
case 3:
|
258
|
-
|
259
|
-
kgtxt.textColor = UIColor.darkGray
|
260
|
-
|
261
|
-
default: break
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
//コードから
|
276
|
-
|
277
|
-
override init(frame: CGRect) {
|
278
|
-
|
279
|
-
super.init(frame: frame)
|
280
|
-
|
281
|
-
self.commonInit()
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
//ストボーから
|
288
|
-
|
289
|
-
required init?(coder aDecoder: NSCoder) {
|
290
|
-
|
291
|
-
super.init(coder: aDecoder)
|
292
|
-
|
293
|
-
self.commonInit()
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
fileprivate func commonInit() {
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
guard let view = UINib(nibName: "CustomAlert", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else {
|
304
|
-
|
305
|
-
return
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
//textfieldに関して
|
312
|
-
|
313
|
-
lepstxt.placeholder = "個数を入力してください。"
|
314
|
-
|
315
|
-
kgtxt.placeholder = "値段を入力してください。"
|
316
|
-
|
317
|
-
lepstxt.font = UIFont(name: "Hiragino Sans", size: 11)
|
318
|
-
|
319
|
-
kgtxt.font = UIFont(name: "Hiragino Sans", size: 11)
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
//デリゲート設定
|
324
|
-
|
325
|
-
lepspicker.delegate = self
|
326
|
-
|
327
|
-
lepspicker.dataSource = self
|
328
|
-
|
329
|
-
//lepspicker.selectedRow(inComponent: 6)
|
330
|
-
|
331
|
-
//lepspicker.backgroundColor = .gray
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
view.frame = self.bounds
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
self.addSubview(view)
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
}
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
@IBAction func cancel(_ sender: Any) {
|
348
|
-
|
349
|
-
self.removeFromSuperview()
|
350
|
-
|
351
|
-
}
|
352
|
-
|
353
|
-
@IBAction func ok(_ sender: Any) {
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
let item = lepstxt.text
|
358
|
-
|
359
|
-
let array = kgtxt.text
|
360
|
-
|
361
|
-
lepslbl.text = String()
|
362
|
-
|
363
|
-
//mytbleView.text = String(item,array)
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
// PickerViewの列数
|
372
|
-
|
373
|
-
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
374
|
-
|
375
|
-
return 1
|
376
|
-
|
377
|
-
}
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
// PickerViewの行数
|
382
|
-
|
383
|
-
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
384
|
-
|
385
|
-
return item.count
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
// PickerViewの項目
|
392
|
-
|
393
|
-
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
394
|
-
|
395
|
-
return item[row]
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
// PickerViewの項目選択時
|
402
|
-
|
403
|
-
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
}
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
```
|
416
|
-
|
417
299
|
|
418
300
|
|
419
301
|

|