回答編集履歴
5
viewWillAppear(_:)
test
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
# viewWillAppearでrefresh()
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
モーダルから戻ってきたときにviewWillAppear(_:)が呼ばれますので、この中でrefresh()を呼ぶようにしましょう。
|
6
|
+
|
7
|
+
モーダルから戻ってきたとき**以外**にもviewWillAppear(_:)は呼ばれますので、`presentedViewController`を見て処理を分岐します。これには、呼び出していたモーダルのViewControllerが入っています。それ以外のときはnilです。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```swift
|
12
|
+
|
13
|
+
override func viewWillAppear(_ animated: Bool) {
|
14
|
+
|
15
|
+
super.viewWillAppear(animated)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
if let presented = self.presentedViewController {
|
20
|
+
|
21
|
+
if type(of: presented) == PopupViewController.self {
|
22
|
+
|
23
|
+
//PopupViewControllerから戻ってきたときはrefresh()
|
24
|
+
|
25
|
+
self.refresh()
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# 旧回答
|
38
|
+
|
39
|
+
|
40
|
+
|
1
41
|
```swift
|
2
42
|
|
3
43
|
guard let parent = storyboard?.instantiateViewController(withIdentifier: "NotificationViewController") as? NotificationViewController else {
|
@@ -26,7 +66,7 @@
|
|
26
66
|
|
27
67
|
|
28
68
|
|
29
|
-
# 別の方法
|
69
|
+
##### 別の方法
|
30
70
|
|
31
71
|
|
32
72
|
|
4
NotificationViewController
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
```swift
|
18
18
|
|
19
|
-
if let parent = self.presentingViewController as?
|
19
|
+
if let parent = self.presentingViewController as? NotificationViewController {
|
20
20
|
|
21
21
|
parent.refresh()
|
22
22
|
|
3
weak
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
これは新しいインスタンスを生成していますので、呼び出し元のNotificationViewControllerとは別物です。なぜselfがnilになるのかまでは調べていません。
|
9
|
+
これは新しいインスタンスを生成していますので、呼び出し元のNotificationViewControllerとは別物です。なぜselfがnilになるのかまでは調べていません。
|
10
10
|
|
11
11
|
|
12
12
|
|
2
self
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
これは新しいインスタンスを生成していますので、呼び出し元のNotificationViewControllerとは別物です。なぜnilになるのかまでは調べていません。
|
9
|
+
これは新しいインスタンスを生成していますので、呼び出し元のNotificationViewControllerとは別物です。なぜselfがnilになるのかまでは調べていません。(そもそもself?って書くのがおかしくないですかね)
|
10
10
|
|
11
11
|
|
12
12
|
|
1
presentingViewController
test
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
```swift
|
2
|
+
|
3
|
+
guard let parent = storyboard?.instantiateViewController(withIdentifier: "NotificationViewController") as? NotificationViewController else {
|
4
|
+
|
5
|
+
```
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
これは新しいインスタンスを生成していますので、呼び出し元のNotificationViewControllerとは別物です。なぜnilになるのかまでは調べていません。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
モーダルの場合は`presentingViewController`で呼び出し元のViewControllerを取得できますので、下記のコードでrefresh()を呼び出せると思います。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```swift
|
18
|
+
|
19
|
+
if let parent = self.presentingViewController as? HybridViewController {
|
20
|
+
|
21
|
+
parent.refresh()
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# 別の方法
|
30
|
+
|
31
|
+
|
32
|
+
|
1
33
|
2日前の出来事です。
|
2
34
|
|
3
35
|
[Swift (Xcode): modal dismissと同時に親Viewを再描画(refresh)させたい](https://teratail.com/questions/148213)
|