質問編集履歴
1
SIGABRTのコンソール表示内容と、それに付随する内容の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,10 +16,120 @@
|
|
16
16
|
|
17
17
|
![イメージ説明](91d4fedec32273eb4e6f9640eb35174f.png)
|
18
18
|
|
19
|
+
```
|
20
|
+
|
21
|
+
2019-11-15 15:45:17.769388+0900 CustomView[11929:367771] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CustomView.ViewController 0x7ff4da504ed0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
以下のコードだと、上記画像のエラーが表示され、またコンソールには上記のように出力されました。
|
26
|
+
|
27
|
+
オブジェクトの接続に問題があると思って確認しましたが、問題なく接続できているように見受けられました。
|
28
|
+
|
29
|
+
自分の判断が間違っている可能性があるので、接続部分の画像も掲載いたします。
|
30
|
+
|
31
|
+
![イメージ説明](db2e8082b0e52098e42257c1bd424a88.png)
|
32
|
+
|
33
|
+
![イメージ説明](f64c4bae8c0041a35b8703543b89713c.png)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
以下がソースコードです。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```ViewController
|
42
|
+
|
43
|
+
import UIKit
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class ViewController: UIViewController {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
weak var customView: UIView!
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
override func viewDidLoad() {
|
56
|
+
|
57
|
+
super.viewDidLoad()
|
58
|
+
|
59
|
+
var customView: CustomView
|
60
|
+
|
61
|
+
customView = Bundle.main.loadNibNamed("CustomView", owner: self, options: nil)!.first! as! CustomView
|
62
|
+
|
63
|
+
customView.label.text = "test"
|
64
|
+
|
65
|
+
self.view.addSubview(customView)
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```CustomView
|
76
|
+
|
77
|
+
import UIKit
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
class CustomView: UIView {
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
@IBOutlet weak var label: UILabel!
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
@IBOutlet weak var `switch`: UISwitch!
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
override func draw(_ rect: CGRect) {
|
94
|
+
|
95
|
+
let selfHight : CGFloat = 200
|
96
|
+
|
97
|
+
let selfWidth : CGFloat = 200
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
self.frame.size.height = selfHight
|
102
|
+
|
103
|
+
self.frame.size.width = selfWidth
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
let superScreen : CGRect = (self.window?.screen.bounds)!
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
self.frame.origin.x = (superScreen.width/2) - (selfWidth/2)
|
112
|
+
|
113
|
+
self.frame.origin.y = (superScreen.height/2) - (selfHight/2)
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
### エラーとソースコードその2
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
![イメージ説明](635ffbc01978e06bcba1e7058ca66a4c.png)
|
130
|
+
|
19
131
|
以下のコードだと、上記画像のエラーが表示されてしまいました。
|
20
132
|
|
21
|
-
各オブジェクトの接続は問題なくできていることは確認しました。
|
22
|
-
|
23
133
|
|
24
134
|
|
25
135
|
```ViewController
|
@@ -30,27 +140,45 @@
|
|
30
140
|
|
31
141
|
class ViewController: UIViewController {
|
32
142
|
|
33
|
-
|
34
|
-
|
143
|
+
|
144
|
+
|
35
|
-
weak var customView:
|
145
|
+
weak var customView: CustomView!
|
36
|
-
|
37
|
-
|
146
|
+
|
147
|
+
|
38
148
|
|
39
149
|
override func viewDidLoad() {
|
40
150
|
|
41
151
|
super.viewDidLoad()
|
42
152
|
|
43
|
-
var customView: CustomView
|
44
|
-
|
45
|
-
customView = Bundle.main.loadNibNamed("CustomView", owner: self, options: nil)!.first! as! CustomView
|
46
|
-
|
47
|
-
customView.label.text = "test"
|
48
|
-
|
49
|
-
self.view.addSubview(customView)
|
50
|
-
|
51
|
-
}
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
52
|
-
|
157
|
+
override func loadView() {
|
158
|
+
|
159
|
+
super.loadView()
|
160
|
+
|
161
|
+
customView = UINib(nibName: "CustomView", bundle: Bundle.main).instantiate(withOwner: self, options: nil).first as? UIView as! CustomView
|
162
|
+
|
163
|
+
customView.backgroundColor = .yellow
|
164
|
+
|
165
|
+
view.addSubview(customView)
|
166
|
+
|
53
|
-
}
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
override func viewDidLayoutSubviews() {
|
172
|
+
|
173
|
+
super.viewDidLayoutSubviews()
|
174
|
+
|
175
|
+
customView.frame = CGRect.init(x: 100.0, y: 100.0, width: 100.0, height: 100.0)
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
54
182
|
|
55
183
|
```
|
56
184
|
|
@@ -66,118 +194,6 @@
|
|
66
194
|
|
67
195
|
|
68
196
|
|
69
|
-
@IBOutlet weak var label: UILabel!
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@IBOutlet weak var `switch`: UISwitch!
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
override func draw(_ rect: CGRect) {
|
78
|
-
|
79
|
-
let selfHight : CGFloat = 200
|
80
|
-
|
81
|
-
let selfWidth : CGFloat = 200
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
self.frame.size.height = selfHight
|
86
|
-
|
87
|
-
self.frame.size.width = selfWidth
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
let superScreen : CGRect = (self.window?.screen.bounds)!
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
self.frame.origin.x = (superScreen.width/2) - (selfWidth/2)
|
96
|
-
|
97
|
-
self.frame.origin.y = (superScreen.height/2) - (selfHight/2)
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
```
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
### エラーとソースコードその2
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
![イメージ説明](635ffbc01978e06bcba1e7058ca66a4c.png)
|
114
|
-
|
115
|
-
以下のコードだと、上記画像のエラーが表示されてしまいました。
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
```ViewController
|
120
|
-
|
121
|
-
import UIKit
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
class ViewController: UIViewController {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
weak var customView: CustomView!
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
override func viewDidLoad() {
|
134
|
-
|
135
|
-
super.viewDidLoad()
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
override func loadView() {
|
142
|
-
|
143
|
-
super.loadView()
|
144
|
-
|
145
|
-
customView = UINib(nibName: "CustomView", bundle: Bundle.main).instantiate(withOwner: self, options: nil).first as? UIView as! CustomView
|
146
|
-
|
147
|
-
customView.backgroundColor = .yellow
|
148
|
-
|
149
|
-
view.addSubview(customView)
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
override func viewDidLayoutSubviews() {
|
156
|
-
|
157
|
-
super.viewDidLayoutSubviews()
|
158
|
-
|
159
|
-
customView.frame = CGRect.init(x: 100.0, y: 100.0, width: 100.0, height: 100.0)
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
```CustomView
|
172
|
-
|
173
|
-
import UIKit
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
class CustomView: UIView {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
197
|
override init(frame: CGRect){
|
182
198
|
|
183
199
|
super.init(frame: frame)
|