回答編集履歴

4

s

2018/07/16 02:53

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- 回答追記
27
+ 回答追記1
28
28
 
29
29
  ---
30
30
 
@@ -53,3 +53,49 @@
53
53
 
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ 回答追記2
60
+
61
+ ---
62
+
63
+
64
+
65
+ viewControllerBが含まれていない場合にViewControllerBを作成してViewControllersを設定しなおす。
66
+
67
+
68
+
69
+ ```swift
70
+
71
+
72
+
73
+ if let navi = navigationController {
74
+
75
+ for vc in navi.viewControllers {
76
+
77
+ if vc is ViewControllerB {
78
+
79
+ navi.popToViewController(vc, animated: true)
80
+
81
+ }
82
+
83
+ }
84
+
85
+
86
+
87
+ // ViewControllersに `B`が含まれていない場合
88
+
89
+ if let viewControllerA = navi.viewControllers.first,
90
+
91
+ let viewControllerB = storyboard?.instantiateViewController(withIdentifier: "viewControllerB") {
92
+
93
+ navigationController?.setViewControllers([viewControllerA,
94
+
95
+ viewControllerB], animated: true)
96
+
97
+ }
98
+
99
+
100
+
101
+ ```

3

s

2018/07/16 02:53

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -21,3 +21,35 @@
21
21
  }
22
22
 
23
23
  ```
24
+
25
+
26
+
27
+ 回答追記
28
+
29
+ ---
30
+
31
+
32
+
33
+ 特定の`ViewController`に遷移したい場合は`viewcontrollers`の中にその`viewController`が含まれているか確認して含まれていればそこに遷移するようにします。
34
+
35
+
36
+
37
+ ```swift
38
+
39
+ if let navi = navigationController {
40
+
41
+ for vc in navi.viewControllers {
42
+
43
+ if vc is ViewControllerC {
44
+
45
+ navi.popToViewController(vc, animated: true)
46
+
47
+ }
48
+
49
+ }
50
+
51
+ }
52
+
53
+
54
+
55
+ ```

2

2018/07/16 01:38

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -6,10 +6,18 @@
6
6
 
7
7
 
8
8
 
9
+ `NavigationController`にぶら下がっている`ViewController`は`navigationController.viewControllers`で取得できるので戻りたい`ViewController`を指定して戻る。
10
+
11
+
12
+
9
13
  ```swift
10
14
 
11
- // NavigationControllerにぶら下がっているViewControllerを指定して戻る
15
+ if let navi = navigationController,
12
16
 
17
+ let firstVC = navi.viewControllers.first {
18
+
13
- navigationController?.popToViewController(navigationController!.viewControllers[1], animated: true)
19
+ navi.popToViewController(firstVC, animated: true)
20
+
21
+ }
14
22
 
15
23
  ```

1

s

2018/07/15 22:11

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  ```swift
10
10
 
11
+ // NavigationControllerにぶら下がっているViewControllerを指定して戻る
12
+
11
13
  navigationController?.popToViewController(navigationController!.viewControllers[1], animated: true)
12
14
 
13
15
  ```