質問編集履歴

1

コードを修正しました。 また、実現したいことの記述が曖昧だったので"1つ前の画面を経由せずに2つ前の画面に直接戻る方法はありますか?"と修正しました。よろしくお願いいたします。

2017/11/29 04:16

投稿

tomoha729
tomoha729

スコア8

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  dismiss()を使うのではなくSegueやpresent()で画面Aに遷移するという方法も考えましたが、都合上適さないため*できれば避けたいです。
16
16
 
17
- 何かいい方法はないでしょうか?たは他に方法がなければ2度のdismiss()を許容べき、諦めて新たに遷移すべきかどちらの処理にすべきでしょうか。
17
+ 1つ前の画面を経由せず2つ前の画面に直接戻る方法はありますか
18
18
 
19
19
 
20
20
 
@@ -24,30 +24,48 @@
24
24
 
25
25
  ###現在のソースコード
26
26
 
27
+ AからBへ遷移する処理。BからB'への遷移は同様にUIStoryboard()のnameを"screenB_2"としています。
28
+
27
29
  ```swift
28
30
 
29
- @IBAction func back(_ sender: Any) {
30
31
 
31
- if needsBackTwice {
32
32
 
33
- //現在の画面からA画面に到達するまでに2度戻る必要があれば2画面分戻る
33
+ @IBAction func transition(_ sender: Any) {
34
34
 
35
- self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)
35
+ let storyboard: UIStoryboard = UIStoryboard(name: "screenB_1", bundle: nil)
36
36
 
37
- } else{
37
+ let nextView = storyboard.instantiateInitialViewController()
38
38
 
39
-   //現在の画面からA画面に到達するまでに2度戻る必要がなければ1画面分戻る
40
-
41
- self.dismiss(animated: false, completion: nil)
39
+ self.present(nextView, animated: false, completion: nil)
42
-
43
- }
44
40
 
45
41
  }
46
42
 
47
43
  ```
48
44
 
45
+ BからAへ戻る処理。
49
46
 
47
+ ```swift
48
+
49
+ @IBAction func backToA(_ sender: Any) {
50
+
51
+ self.dismiss(animated: false, completion: nil)
52
+
53
+ }
54
+
55
+ ```
56
+
57
+ B'からAへ戻る処理。
58
+
59
+ ```swift
60
+
61
+ @IBAction func backToA(_ sender: Any) {
62
+
63
+ self.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)
64
+
65
+ }
66
+
67
+ ```
50
68
 
51
69
  ###補足情報
52
70
 
53
- Swift4です。よろしくお願いいたします。
71
+ Swift4です。