回答編集履歴

1

naviらない。

2017/03/01 04:37

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -1 +1,73 @@
1
1
  popToRootViewController(animated:)で最初のViewControllerまで戻れますが、CollectionViewControllerがModalのようなので、dismiss(animated:completion:)してからpopToRootViewController(animated:)を呼ばないといけないかも知れません。
2
+
3
+
4
+
5
+ # UINavigationControllerを使用しない
6
+
7
+
8
+
9
+ 3→2から2→1へ無理やり繋げてみました。
10
+
11
+ Swift3化したつもりですが、エラーが出たら適当に直して下さい。
12
+
13
+
14
+
15
+ 戻るときのアニメーションについては、dismissのtrue/falseで調整して下さい。
16
+
17
+
18
+
19
+ ##### SecondViewController
20
+
21
+
22
+
23
+ ```swift
24
+
25
+ override func viewWillAppear(animated: Bool) {
26
+
27
+ super.viewWillAppear(animated)
28
+
29
+ if let presented = presentedViewController {
30
+
31
+ if type(of: presented) == CollectionViewController.self {
32
+
33
+ //CollectionViewControllerから戻ってきたときの処理
34
+
35
+ print("[2] dismiss!")
36
+
37
+ dismiss(animated: true) {
38
+
39
+ print("[2] dismissed.")
40
+
41
+ }
42
+
43
+ }
44
+
45
+ }
46
+
47
+ }
48
+
49
+ ```
50
+
51
+
52
+
53
+ ##### CollectionViewController
54
+
55
+
56
+
57
+ ```swift
58
+
59
+ @IBAction func tapped(sender: UIButton) {
60
+
61
+ print("[3] dismiss!")
62
+
63
+ dismiss(animated: true) {
64
+
65
+ print("[3] dismissed")
66
+
67
+ }
68
+
69
+ }
70
+
71
+ ```
72
+
73
+