質問編集履歴
1
回答者にわかりやすいように補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,179 @@
|
|
1
|
+
```swift
|
2
|
+
|
3
|
+
import UIKit
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
let TODO2 = ["Youtube", "Buzzvideo", "Instagram","Twitter","ニコニコ動画","FC2動画","Google"]
|
12
|
+
|
13
|
+
let parameters = ["Youtube": "Buzzvideo", "Instagram": "Twitter","ニコニコ動画":"FC2動画"]
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
@IBOutlet weak var menuView: UITableView!
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
override func viewDidLoad() {
|
22
|
+
|
23
|
+
super.viewDidLoad()
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
func segueToFirstViewController() {
|
30
|
+
|
31
|
+
self.performSegue(withIdentifier: "toFirstViewController", sender: self.parameters)
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
38
|
+
|
39
|
+
if segue.identifier == "toFirstViewController" {
|
40
|
+
|
41
|
+
let MenuViewController = segue.destination as! MenuViewController
|
42
|
+
|
43
|
+
FirstViewController.parameters = sender as! [String : String]
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
menuView.delegate = self
|
50
|
+
|
51
|
+
menuView.dataSource = self
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
override func didReceiveMemoryWarning() {
|
58
|
+
|
59
|
+
super.didReceiveMemoryWarning()
|
60
|
+
|
61
|
+
// Dispose of any resources that can be recreated.
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
override func viewWillAppear(_ animated: Bool)
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
super.viewWillAppear(animated)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
let menuPos = self.menuView.layer.position
|
76
|
+
|
77
|
+
self.menuView.layer.position.x = -self.menuView.frame.width
|
78
|
+
|
79
|
+
UIView.animate(
|
80
|
+
|
81
|
+
withDuration: 0.5,
|
82
|
+
|
83
|
+
delay: 0,
|
84
|
+
|
85
|
+
options: .curveEaseOut,
|
86
|
+
|
87
|
+
animations: {
|
88
|
+
|
89
|
+
self.menuView.layer.position.x = menuPos.x
|
90
|
+
|
91
|
+
},
|
92
|
+
|
93
|
+
completion: { bool in})
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
super.touchesEnded(touches, with: event)
|
104
|
+
|
105
|
+
for touch in touches
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
if touch.view?.tag == 1
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
UIView.animate(withDuration: 0.2,
|
114
|
+
|
115
|
+
delay: 0,
|
116
|
+
|
117
|
+
options: .curveEaseIn,
|
118
|
+
|
119
|
+
animations:
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
self.menuView.layer.position.x = -self.menuView.frame.width
|
124
|
+
|
125
|
+
},
|
126
|
+
|
127
|
+
completion:
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
bool in self.dismiss(animated: true, completion: nil)
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
)
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//追加③ セルの個数を指定するデリゲートメソッド(必須)
|
150
|
+
|
151
|
+
func tableView(_ menuView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
152
|
+
|
153
|
+
return TODO2.count
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//追加④ セルに値を設定するデータソースメソッド(必須)
|
160
|
+
|
161
|
+
func tableView(_ menuView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
162
|
+
|
163
|
+
// セルを取得する
|
164
|
+
|
165
|
+
let cell: UITableViewCell = menuView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
166
|
+
|
167
|
+
// セルに表示する値を設定する
|
168
|
+
|
169
|
+
cell.textLabel!.text = TODO2[indexPath.row]
|
170
|
+
|
171
|
+
return cell
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
1
|
-
![![イメージ説明](29962e4f601365878a6e210eff9728d7.png)]
|
177
|
+
```![![イメージ説明](29962e4f601365878a6e210eff9728d7.png)]
|
2
178
|
|
3
179
|
> 上記の写真のようにサイドメニューから各サービスをブラウザで開きたいのですがtableviewは最初に表示するFirstViewControllerではなく専用のMenuViewControllerで繋いでるのでどこに画面移行するコードを持って行ってよいかわかりません。どなたか教えていただけると嬉しいです。説明不足や意味不明と言う場合も返信を下されば説明し直します。どうかよろしくお願いします。
|