回答編集履歴
3
Show
answer
CHANGED
@@ -43,3 +43,17 @@
|
|
43
43
|
self.dismissViewControllerAnimated(true, completion: nil)
|
44
44
|
}
|
45
45
|
```
|
46
|
+
|
47
|
+
###### 【おまけ】Showの場合
|
48
|
+
|
49
|
+
```swift
|
50
|
+
//Navigation Controllerを取得
|
51
|
+
let nav = self.navigationController!
|
52
|
+
|
53
|
+
//呼び出し元のView Controllerを遷移履歴から取得しパラメータを渡す
|
54
|
+
let InfoVc = nav.viewControllers[nav.viewControllers.count-2] as! FirstViewController
|
55
|
+
InfoVc.paramCellNum = arrayHistoryEventKey[indexPath.row]
|
56
|
+
|
57
|
+
//閉じる
|
58
|
+
self.navigationController?.popViewControllerAnimated(true)
|
59
|
+
```
|
2
回答修正および清書。
answer
CHANGED
@@ -4,16 +4,18 @@
|
|
4
4
|
|
5
5
|
# 本題
|
6
6
|
|
7
|
-
HistoryViewControllerが**Present Modally**で呼ばれていると仮定し
|
7
|
+
HistoryViewControllerが**Present Modally**で呼ばれていると仮定します。
|
8
8
|
|
9
|
+
## Navigation Controllerを使用していない場合
|
10
|
+
|
11
|
+
こちらは簡単です。
|
12
|
+
呼び出し元は`presentingViewController`で取得できますので、
|
13
|
+
|
9
14
|
```swift
|
10
15
|
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
11
16
|
|
12
|
-
//遷移元にパラメータを渡す
|
13
|
-
//
|
17
|
+
//呼び出し元のView Controllerを取得しパラメータを渡す
|
14
|
-
|
18
|
+
let InfoVc = self.presentingViewController as! FirstViewController
|
15
|
-
//NavigationControllerを使っている場合
|
16
|
-
let InfoVc = self.navigationController.viewControllers[self.navigationController.viewControllers.count-2] as! FirstViewController
|
17
19
|
InfoVc.paramCellNum = arrayHistoryEventKey[indexPath.row]
|
18
20
|
|
19
21
|
//閉じる
|
@@ -21,4 +23,23 @@
|
|
21
23
|
}
|
22
24
|
```
|
23
25
|
|
26
|
+
## Navigation Controllerを使用している場合
|
27
|
+
|
28
|
+
こちらはちょっと面倒です。
|
29
|
+
`presentingViewController`にはNavigation Controllerが入っていますので、まずそれを取得します。
|
30
|
+
Navigation Controllerの`viewControllers`には、今までの遷移履歴が入っていますので、そこから呼び出し元(履歴の最後)のView Controllerを取得します。
|
31
|
+
|
24
|
-
|
32
|
+
```swift
|
33
|
+
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
34
|
+
|
35
|
+
//Navigation Controllerを取得
|
36
|
+
let nav = self.presentingViewController as! UINavigationController
|
37
|
+
|
38
|
+
//呼び出し元のView Controllerを遷移履歴から取得しパラメータを渡す
|
39
|
+
let InfoVc = nav.viewControllers[nav.viewControllers.count-1] as! FirstViewController
|
40
|
+
InfoVc.paramCellNum = arrayHistoryEventKey[indexPath.row]
|
41
|
+
|
42
|
+
//閉じる
|
43
|
+
self.dismissViewControllerAnimated(true, completion: nil)
|
44
|
+
}
|
45
|
+
```
|
1
NavigationController使用。
answer
CHANGED
@@ -10,7 +10,10 @@
|
|
10
10
|
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
11
11
|
|
12
12
|
//遷移元にパラメータを渡す
|
13
|
+
//NavigationControllerを使っていない場合
|
13
|
-
let InfoVc = self.presentingViewController as! FirstViewController
|
14
|
+
//let InfoVc = self.presentingViewController as! FirstViewController
|
15
|
+
//NavigationControllerを使っている場合
|
16
|
+
let InfoVc = self.navigationController.viewControllers[self.navigationController.viewControllers.count-2] as! FirstViewController
|
14
17
|
InfoVc.paramCellNum = arrayHistoryEventKey[indexPath.row]
|
15
18
|
|
16
19
|
//閉じる
|