質問編集履歴
8
画像の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -353,7 +353,3 @@
|
|
353
353
|
**参考URL**
|
354
354
|
|
355
355
|
https://dev.classmethod.jp/smartphone/xib/
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-

|
7
写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -354,10 +354,6 @@
|
|
354
354
|
|
355
355
|
https://dev.classmethod.jp/smartphone/xib/
|
356
356
|
|
357
|
-
|
357
|
+
|
358
|
-
|
359
|
-
|
358
|
+
|
360
|
-
|
361
|
-

|
362
|
-
|
363
|
-

|
6
写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -359,3 +359,5 @@
|
|
359
359
|

|
360
360
|
|
361
361
|

|
362
|
+
|
363
|
+

|
5
最新のコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,108 +1,294 @@
|
|
1
1
|
**viewcontroller.swift**
|
2
2
|
|
3
|
+
```import UIKit
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource{
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
var pickerView = UIPickerView()
|
12
|
+
|
13
|
+
let number = ["回","lep"]
|
14
|
+
|
15
|
+
let datalist2 = ["kg","lbs"]
|
16
|
+
|
17
|
+
@IBAction func customalertbtr(_ sender: Any) {
|
18
|
+
|
19
|
+
/*let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 300 , height: 200))
|
20
|
+
|
21
|
+
view.backgroundColor = .orange
|
22
|
+
|
23
|
+
self.view.addSubview(view)*/
|
24
|
+
|
25
|
+
let customAlert = CustomAlert(frame: CGRect(x: 0.0, y: 0.0, width: 350 , height: 350))
|
26
|
+
|
27
|
+
customAlert.center = self.view.center
|
28
|
+
|
29
|
+
customAlert.backgroundColor = .orange
|
30
|
+
|
31
|
+
print(customAlert) //これ追加
|
32
|
+
|
33
|
+
self.view.addSubview(customAlert)
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
@IBAction func btr(_ sender: Any) {
|
38
|
+
|
39
|
+
let alert = UIAlertController(title: "値を入力してください", message: "\n\n\n\n\n\n\n\n", preferredStyle: .alert)
|
40
|
+
|
41
|
+
// テキストフィールドを追加
|
42
|
+
|
43
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
44
|
+
|
45
|
+
textField.placeholder = "回数を入力してください。"
|
46
|
+
|
47
|
+
})
|
48
|
+
|
49
|
+
//二個目
|
50
|
+
|
51
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
52
|
+
|
53
|
+
textField.placeholder = "重量を入力してください。"
|
54
|
+
|
55
|
+
})
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
let saveAction = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction!) -> Void in
|
60
|
+
|
61
|
+
//self.mytableView.reloadData()
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
let cancelAction = UIAlertAction(title: "キャンセル", style: .default) { (action:UIAlertAction!) -> Void in
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
//PickerView
|
72
|
+
|
73
|
+
pickerView = UIPickerView(frame:CGRect(x:0, y:50, width:view.bounds.width*0.6, height:300)) // 配置、サイズ
|
74
|
+
|
75
|
+
pickerView.frame = CGRect(x:0, y:0, width:view.bounds.width*0.7, height:280)
|
76
|
+
|
77
|
+
pickerView.dataSource = self
|
78
|
+
|
79
|
+
pickerView.delegate = self
|
80
|
+
|
81
|
+
alert.view.addSubview(pickerView)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
alert.addAction(saveAction)
|
86
|
+
|
87
|
+
alert.addAction(cancelAction)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
present(alert, animated: true, completion: nil)
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
// PickerViewの列数
|
96
|
+
|
97
|
+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
98
|
+
|
99
|
+
return 2
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// PickerViewの行数
|
106
|
+
|
107
|
+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
108
|
+
|
109
|
+
if component == 0 {
|
110
|
+
|
111
|
+
// 1個目のピッカーの設定
|
112
|
+
|
113
|
+
return number.count
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
return datalist2.count
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
// PickerViewの項目
|
124
|
+
|
125
|
+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
126
|
+
|
127
|
+
if component == 0 {
|
128
|
+
|
129
|
+
return number[row]
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
return datalist2[row]
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// PickerViewの項目選択時
|
140
|
+
|
141
|
+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
override func viewDidLoad() {
|
152
|
+
|
153
|
+
super.viewDidLoad()
|
154
|
+
|
155
|
+
// Do any additional setup after loading the view, typically from a nib.
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
override func didReceiveMemoryWarning() {
|
162
|
+
|
163
|
+
super.didReceiveMemoryWarning()
|
164
|
+
|
165
|
+
// Dispose of any resources that can be recreated.
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
|
180
|
+
|
3
|
-
|
181
|
+
custom alert.swift
|
182
|
+
|
183
|
+
```
|
4
184
|
|
5
185
|
import UIKit
|
6
186
|
|
7
187
|
|
8
188
|
|
9
|
-
class
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
let
|
20
|
-
|
21
|
-
let
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@IB
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
189
|
+
class CustomAlert: UIView ,UIPickerViewDataSource,UIPickerViewDelegate {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
let item = ["円","ドル"]
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
@IBOutlet var myView: UIView!
|
200
|
+
|
201
|
+
@IBOutlet weak var titlelbl: UILabel!
|
202
|
+
|
203
|
+
@IBOutlet weak var exlbl: UILabel!
|
204
|
+
|
205
|
+
@IBOutlet weak var lepslbl: UITextField!
|
206
|
+
|
207
|
+
@IBOutlet weak var kg: UITextField!
|
208
|
+
|
209
|
+
@IBOutlet weak var times: UILabel!
|
210
|
+
|
211
|
+
@IBOutlet weak var sub: UIPickerView!
|
212
|
+
|
213
|
+
@IBOutlet weak var kgandlbs: UISegmentedControl!
|
214
|
+
|
215
|
+
@IBOutlet weak var lownormalhigh: UISegmentedControl!
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
//コードから
|
220
|
+
|
221
|
+
override init(frame: CGRect) {
|
222
|
+
|
223
|
+
super.init(frame: frame)
|
224
|
+
|
225
|
+
//self.commonInit()
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
//ストボーから
|
232
|
+
|
233
|
+
required init?(coder aDecoder: NSCoder) {
|
234
|
+
|
235
|
+
super.init(coder: aDecoder)
|
236
|
+
|
237
|
+
//self.commonInit()
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
fileprivate func commonInit() {
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
guard let view = UINib(nibName: "CustomAlert", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else {
|
248
|
+
|
249
|
+
return
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
/*/ デリゲート設定
|
256
|
+
|
257
|
+
sub.delegate = self
|
258
|
+
|
259
|
+
sub.dataSource = self*/
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
//view.frame = self.bounds
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
self.addSubview(view)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
@IBAction func cancelbtr(_ sender: Any) {
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
@IBAction func okbtr(_ sender: Any) {
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
100
286
|
|
101
287
|
// PickerViewの列数
|
102
288
|
|
103
289
|
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
104
290
|
|
105
|
-
return
|
291
|
+
return 1
|
106
292
|
|
107
293
|
}
|
108
294
|
|
@@ -112,15 +298,7 @@
|
|
112
298
|
|
113
299
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
114
300
|
|
115
|
-
if component == 0 {
|
116
|
-
|
117
|
-
// 1個目のピッカーの設定
|
118
|
-
|
119
|
-
|
301
|
+
return item.count
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
return datalist2.count
|
124
302
|
|
125
303
|
}
|
126
304
|
|
@@ -130,13 +308,7 @@
|
|
130
308
|
|
131
309
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
132
310
|
|
133
|
-
if component == 0 {
|
134
|
-
|
135
|
-
|
311
|
+
return item[row]
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
return datalist2[row]
|
140
312
|
|
141
313
|
}
|
142
314
|
|
@@ -154,28 +326,6 @@
|
|
154
326
|
|
155
327
|
|
156
328
|
|
157
|
-
override func viewDidLoad() {
|
158
|
-
|
159
|
-
super.viewDidLoad()
|
160
|
-
|
161
|
-
// Do any additional setup after loading the view, typically from a nib.
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
override func didReceiveMemoryWarning() {
|
168
|
-
|
169
|
-
super.didReceiveMemoryWarning()
|
170
|
-
|
171
|
-
// Dispose of any resources that can be recreated.
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
329
|
}
|
180
330
|
|
181
331
|
|
@@ -184,156 +334,6 @@
|
|
184
334
|
|
185
335
|
|
186
336
|
|
187
|
-
custom alert.swift
|
188
|
-
|
189
|
-
```
|
190
|
-
|
191
|
-
import UIKit
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
class CustomAlert: UIView ,UIPickerViewDataSource,UIPickerViewDelegate {
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
//let item = ["円","ドル"]
|
200
|
-
|
201
|
-
let item = ["-5","-4","-3","-2","-1","0","1","2","3","4","5"]
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
@IBOutlet var _myview: UIView!
|
206
|
-
|
207
|
-
@IBOutlet weak var titlelbl: UILabel!
|
208
|
-
|
209
|
-
@IBOutlet weak var exlbl: UILabel!
|
210
|
-
|
211
|
-
@IBOutlet weak var lepslbl: UILabel!
|
212
|
-
|
213
|
-
@IBOutlet weak var leps: UITextField!
|
214
|
-
|
215
|
-
@IBOutlet weak var kg: UITextField!
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
//コードから
|
222
|
-
|
223
|
-
override init(frame: CGRect) {
|
224
|
-
|
225
|
-
super.init(frame: frame)
|
226
|
-
|
227
|
-
self.commonInit()
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
//ストボーから
|
234
|
-
|
235
|
-
required init?(coder aDecoder: NSCoder) {
|
236
|
-
|
237
|
-
super.init(coder: aDecoder)
|
238
|
-
|
239
|
-
self.commonInit()
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
fileprivate func commonInit() {
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
guard let view = UINib(nibName: "CustomAlert", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else {
|
250
|
-
|
251
|
-
return
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
/*// デリゲート設定
|
258
|
-
|
259
|
-
sub.delegate = self
|
260
|
-
|
261
|
-
sub.dataSource = self*/
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
view.frame = self.bounds
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
self.addSubview(view)
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
@IBAction func cancelbtr(_ sender: Any) {
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
@IBAction func okbtr(_ sender: Any) {
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
// PickerViewの列数
|
288
|
-
|
289
|
-
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
290
|
-
|
291
|
-
return 1
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
// PickerViewの行数
|
298
|
-
|
299
|
-
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
300
|
-
|
301
|
-
return item.count
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
// PickerViewの項目
|
308
|
-
|
309
|
-
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
310
|
-
|
311
|
-
return item[row]
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
// PickerViewの項目選択時
|
318
|
-
|
319
|
-
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
```
|
334
|
-
|
335
|
-
|
336
|
-
|
337
337
|
**やりたいこと**
|
338
338
|
|
339
339
|
自分で作ったカスタムアラートを呼び出せるようにしたいです。
|
@@ -354,14 +354,8 @@
|
|
354
354
|
|
355
355
|
https://dev.classmethod.jp/smartphone/xib/
|
356
356
|
|
357
|
-
|
358
|
-
|
359
|
-

|
360
|
-
|
358
|
+
|
361
|
-

|
362
|
-
|
360
|
+
|
363
|
-

|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-

|
4
consoleについて
test
CHANGED
File without changes
|
test
CHANGED
@@ -360,4 +360,8 @@
|
|
360
360
|
|
361
361
|

|
362
362
|
|
363
|
+

|
364
|
+
|
365
|
+
|
366
|
+
|
363
|
-

|
3
改善点についての説明
test
CHANGED
File without changes
|
test
CHANGED
@@ -342,9 +342,11 @@
|
|
342
342
|
|
343
343
|
**困っていること**
|
344
344
|
|
345
|
-
コード内でのコードエラーはないが実行していざ呼び出そうとするとsignal sigabrtになってしまいます。
|
345
|
+
~~コード内でのコードエラーはないが実行していざ呼び出そうとするとsignal sigabrtになってしまいます~~。
|
346
|
-
|
346
|
+
|
347
|
-
おそらくviewcontroller.swiftでの呼び出しについてのコードがよくないのかなと考えらえれるのですがどこがダメなのか分からなく困っています。
|
347
|
+
~~おそらくviewcontroller.swiftでの呼び出しについてのコードがよくないのかなと考えらえれるのですがどこがダメなのか分からなく困っています。~~
|
348
|
+
|
349
|
+
xibのファイル名をcustomAlertに変更したらsignal sigabrtで強制終了はされなくはなったのですが以前alertが呼び出されずに困っています。
|
348
350
|
|
349
351
|
|
350
352
|
|
@@ -357,3 +359,5 @@
|
|
357
359
|

|
358
360
|
|
359
361
|

|
362
|
+
|
363
|
+

|
2
写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -351,3 +351,9 @@
|
|
351
351
|
**参考URL**
|
352
352
|
|
353
353
|
https://dev.classmethod.jp/smartphone/xib/
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+

|
358
|
+
|
359
|
+

|
1
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -345,3 +345,9 @@
|
|
345
345
|
コード内でのコードエラーはないが実行していざ呼び出そうとするとsignal sigabrtになってしまいます。
|
346
346
|
|
347
347
|
おそらくviewcontroller.swiftでの呼び出しについてのコードがよくないのかなと考えらえれるのですがどこがダメなのか分からなく困っています。
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
**参考URL**
|
352
|
+
|
353
|
+
https://dev.classmethod.jp/smartphone/xib/
|