質問編集履歴
2
丁寧に文章を書く
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
押したらtop画面へ行くボタンを作りたくてコードを書きましたが
|
1
|
+
rankingViewControllerに押したらtop画面(topViewController)へ行くボタンを作りたくてコードを書きましたがlet storyboard:UIStoryboard = self.storyboard!のところでnilだというエラーが出ます。
|
2
2
|
|
3
|
-
ちなみにnavigationcontrollerとsegueが設定されています。
|
3
|
+
ちなみにstoryboardではnavigationcontrollerとsegueが設定されています。
|
4
4
|
|
5
5
|
よろしくお願いします。
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
```swift
|
10
|
+
|
11
|
+
class RankingViewController: UIViewController {
|
12
|
+
|
13
|
+
|
10
14
|
|
11
15
|
//ホームボタン
|
12
16
|
|
@@ -44,4 +48,6 @@
|
|
44
48
|
|
45
49
|
}
|
46
50
|
|
51
|
+
}
|
52
|
+
|
47
53
|
```
|
1
コードの詳細を書く
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,14 +8,40 @@
|
|
8
8
|
|
9
9
|
```swift
|
10
10
|
|
11
|
+
//ホームボタン
|
12
|
+
|
13
|
+
let homeButton = UIButton()
|
14
|
+
|
15
|
+
homeButton.frame = CGRect(x:0,y:0,width:viewWidth/3,height:margin/2)
|
16
|
+
|
11
|
-
|
17
|
+
homeButton.backgroundColor = UIColor.gray
|
18
|
+
|
19
|
+
homeButton.setTitle("ホームへ", for: .normal)
|
20
|
+
|
21
|
+
homeButton.addTarget(nil, action: #selector(RankingViewController.gotoHomeButton), for: .touchUpInside)
|
22
|
+
|
23
|
+
self.view.addSubview(homeButton)
|
12
24
|
|
13
25
|
|
14
26
|
|
15
|
-
|
27
|
+
@objc func gotoHomeButton(_ sender: Any){
|
16
28
|
|
17
|
-
|
29
|
+
|
18
30
|
|
31
|
+
let storyboard:UIStoryboard = self.storyboard!
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
let topVC = storyboard.instantiateViewController(withIdentifier: "Top") as! TopViewController
|
36
|
+
|
37
|
+
|
38
|
+
|
19
|
-
self.present(topVC,animated:true, completion:nil)
|
39
|
+
self.present(topVC,animated:true, completion:nil)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
}
|
20
46
|
|
21
47
|
```
|