回答編集履歴
1
回答追記
test
CHANGED
@@ -53,3 +53,41 @@
|
|
53
53
|
|
54
54
|
|
55
55
|
のような感じで適切にダウンキャストすれば、エラー(コンパイル前の警告)も出ず、また値も渡されると思います(もちろん、遷移先で適切に処理しなければいけませんが)。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
---
|
60
|
+
|
61
|
+
遷移先が NavigationController であり、かつスタックの先頭に移動するのであれば
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```Swift
|
66
|
+
|
67
|
+
if let nextVC = tabBarController?.viewControllers?[2] as? UINavigationController {
|
68
|
+
|
69
|
+
if let topVC = nextVC.topViewController as? ThirdViewController {
|
70
|
+
|
71
|
+
topVC.previousVC = 1
|
72
|
+
|
73
|
+
tabBarController?.selectedViewController = nextVC
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
このような感じでしょうか。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
まずは、遷移先が UINavigationController か否かを判断し、次に NavigationController (のスタックの)の先頭に入っている View Controller が ThirdViewController か判断し、そうであれば値を入れるという具合です。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
- [topViewController - The view controller at the top of the navigation stack.](https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621849-topviewcontroller)
|