質問編集履歴
3
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,15 +4,21 @@
|
|
4
4
|
8.0もビルドしたくて、インストールしたのですが、
|
5
5
|
|
6
6
|
```
|
7
|
+
import UIKit
|
8
|
+
|
7
|
-
class CustomView: UIView {
|
9
|
+
class CustomView: UIView {
|
10
|
+
|
8
11
|
override init(frame: CGRect) {
|
9
12
|
super.init(frame: frame)
|
13
|
+
backgroundColor = UIColor.whiteColor()
|
14
|
+
let button = UIButton()
|
15
|
+
button.frame.size = CGSize(width: 100, height: 100)
|
16
|
+
button.frame.origin = CGPoint(x: 100, y: 100)
|
17
|
+
button.backgroundColor = UIColor.blueColor()
|
10
18
|
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
11
|
-
button.frame.size = CGSize(width: 61, height: 61)
|
12
|
-
button.frame.origin = CGPoint(x: 100, y: 100)
|
13
|
-
self.
|
19
|
+
self.addSubview(button)
|
14
20
|
}
|
15
|
-
|
21
|
+
|
16
22
|
required init?(coder aDecoder: NSCoder) {
|
17
23
|
fatalError("init(coder:) has not been implemented")
|
18
24
|
}
|
2
コードの書き換え
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,15 +3,23 @@
|
|
3
3
|
今までsimulatorのバージョン9.3.1でビルドしてたのですが、
|
4
4
|
8.0もビルドしたくて、インストールしたのですが、
|
5
5
|
|
6
|
+
```
|
6
7
|
class CustomView: UIView {
|
7
|
-
@IBOutlet weak button: UIButton!
|
8
|
-
|
9
8
|
override init(frame: CGRect) {
|
10
9
|
super.init(frame: frame)
|
11
|
-
|
10
|
+
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
11
|
+
button.frame.size = CGSize(width: 61, height: 61)
|
12
|
+
button.frame.origin = CGPoint(x: 100, y: 100)
|
13
|
+
self.addSubView(button)
|
12
14
|
}
|
15
|
+
|
16
|
+
required init?(coder aDecoder: NSCoder) {
|
17
|
+
fatalError("init(coder:) has not been implemented")
|
18
|
+
}
|
13
19
|
}
|
20
|
+
```
|
14
21
|
|
22
|
+
```
|
15
23
|
class ViewController: UIViewController {
|
16
24
|
override func loadView() {
|
17
25
|
super.loadView()
|
@@ -20,9 +28,10 @@
|
|
20
28
|
}
|
21
29
|
|
22
30
|
func tapButton() {
|
23
|
-
print("call")
|
31
|
+
print("call")
|
32
|
+
}
|
24
33
|
}
|
25
|
-
|
34
|
+
```
|
26
35
|
|
27
36
|
このコードがiOS9.3だと大丈夫なのですが、ios8.1のシュミレーターだと落ちてしまいます。
|
28
37
|
原因がわかる方いらっしゃいますか?
|
1
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,13 +3,24 @@
|
|
3
3
|
今までsimulatorのバージョン9.3.1でビルドしてたのですが、
|
4
4
|
8.0もビルドしたくて、インストールしたのですが、
|
5
5
|
|
6
|
-
class
|
6
|
+
class CustomView: UIView {
|
7
|
+
@IBOutlet weak button: UIButton!
|
8
|
+
|
9
|
+
override init(frame: CGRect) {
|
10
|
+
super.init(frame: frame)
|
7
11
|
button.addTarget(ViewController(), action: #selector(ViewController.tapButton), forControlEvents: .TouchUpInside)
|
12
|
+
}
|
8
13
|
}
|
9
14
|
|
10
|
-
|
15
|
+
class ViewController: UIViewController {
|
11
|
-
|
16
|
+
override func loadView() {
|
17
|
+
super.loadView()
|
18
|
+
let customView = CustomView(frame: view.frame)
|
19
|
+
self.view = customView
|
20
|
+
}
|
12
21
|
|
22
|
+
func tapButton() {
|
23
|
+
print("call")
|
13
24
|
}
|
14
25
|
}
|
15
26
|
|