質問編集履歴
3
こード記入
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
|
22
22
|
サンプルでは、配列soundNameArray内の1つの配列に16コのmp3データがあり、ページ数は20ページあります。
|
23
23
|
サンプルでは、2種類のmp3データを使い回して試しています。(ファイル名は1.mp3、2.mp3)
|
24
|
-
サンプルでは、tableViewのセルから画面遷移して遷移先のページから音の再生やページスクロール
|
24
|
+
サンプルでは、tableViewのセルから画面遷移して遷移先のページから音の再生やページスクロールする仕様にしています。
|
25
25
|
```
|
26
26
|
// 使用Version: Swift3
|
27
27
|
import UIKit
|
2
コード記入
title
CHANGED
File without changes
|
body
CHANGED
@@ -151,112 +151,4 @@
|
|
151
151
|
super.didReceiveMemoryWarning()
|
152
152
|
}
|
153
153
|
}
|
154
|
-
```
|
155
|
-
|
156
|
-
###その他のソースコード(ページングするためのViewControllerとPageViewController)
|
157
|
-
```
|
158
|
-
import UIKit
|
159
|
-
|
160
|
-
class PageViewController: UIPageViewController, UIPageViewControllerDataSource {
|
161
|
-
|
162
|
-
var selectedIndex: Int = 0 // タップされたセルのindex
|
163
|
-
var pageIndex:Int = 0 // 各ページに割り当てたindex
|
164
|
-
var contentVCs = [UIViewController]()
|
165
|
-
|
166
|
-
override func viewDidLoad() {
|
167
|
-
super.viewDidLoad()
|
168
|
-
|
169
|
-
// ナビゲーションバーの透過を無効にする。
|
170
|
-
self.navigationController!.navigationBar.isTranslucent = false
|
171
|
-
|
172
|
-
dataSource = self
|
173
|
-
|
174
|
-
for index in 0..<20 {
|
175
|
-
let contentVC = storyboard?.instantiateViewController(withIdentifier: "PageContentViewController") as! PageContentViewController
|
176
|
-
contentVC.pageIndex = index
|
177
|
-
contentVCs.append(contentVC)
|
178
|
-
}
|
179
|
-
|
180
|
-
self.setViewControllers([contentVCs[selectedIndex]], direction: .forward, animated: true, completion: nil)
|
181
|
-
|
182
|
-
} // viewDidLoad()を閉じる
|
183
|
-
|
184
|
-
|
185
|
-
// MARK: - UIPageViewControllerDataSource
|
186
|
-
// スワイプでページを戻る(Before)
|
187
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
188
|
-
guard let index = contentVCs.index(of: viewController as! PageContentViewController), index > 0 else {
|
189
|
-
return nil
|
190
|
-
}
|
191
|
-
let previousVC = contentVCs[index - 1]
|
192
|
-
return previousVC
|
193
|
-
}
|
194
|
-
|
195
|
-
// スワイプでページを進む(After)
|
196
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
197
|
-
guard let index = contentVCs.index(of: viewController as! PageContentViewController), index < contentVCs.count - 1 else {
|
198
|
-
return nil
|
199
|
-
}
|
200
|
-
let nextVC = contentVCs[index + 1]
|
201
|
-
return nextVC
|
202
|
-
}
|
203
|
-
|
204
|
-
}
|
205
|
-
```
|
206
|
-
```
|
207
|
-
import UIKit
|
208
|
-
|
209
|
-
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
210
|
-
|
211
|
-
let sectionTitle = ["Title"] //セクションに表示するデータ
|
212
|
-
let section0 = Array(1...20) //セルに表示するデータ
|
213
|
-
|
214
|
-
@IBOutlet weak var tableView: UITableView!
|
215
|
-
|
216
|
-
override func viewDidLoad() {
|
217
|
-
super.viewDidLoad()
|
218
|
-
|
219
|
-
tableView.delegate = self
|
220
|
-
tableView.dataSource = self
|
221
|
-
}
|
222
|
-
|
223
|
-
override func didReceiveMemoryWarning() {
|
224
|
-
super.didReceiveMemoryWarning()
|
225
|
-
}
|
226
|
-
|
227
|
-
func numberOfSections(in tableView: UITableView) -> Int {
|
228
|
-
return sectionTitle.count
|
229
|
-
}
|
230
|
-
|
231
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
232
|
-
return section0.count
|
233
|
-
}
|
234
|
-
|
235
|
-
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
236
|
-
return sectionTitle[section]
|
237
|
-
}
|
238
|
-
|
239
|
-
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
240
|
-
return 30
|
241
|
-
}
|
242
|
-
|
243
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
244
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
245
|
-
cell.textLabel?.text = "(section0[indexPath.row])"
|
246
|
-
return cell
|
247
|
-
}
|
248
|
-
|
249
|
-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
250
|
-
if segue.identifier == "ToPageViewController" {
|
251
|
-
if let indexPath = self.tableView.indexPathForSelectedRow {
|
252
|
-
tableView.deselectRow(at: indexPath, animated: false)
|
253
|
-
if let pageViewController = segue.destination as? PageViewController {
|
254
|
-
pageViewController.selectedIndex = indexPath.row
|
255
|
-
}
|
256
|
-
}
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
}
|
261
|
-
|
262
154
|
```
|
1
コード記入
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
import UIKit
|
28
28
|
import AVFoundation
|
29
29
|
|
30
|
-
class PageContentViewController: UIViewController,
|
30
|
+
class PageContentViewController: UIViewController, AVAudioPlayerDelegate {
|
31
31
|
|
32
32
|
let soundNameArray = [
|
33
33
|
["1","2","1","2","1","2","1","2","1","2","1","2","1","2","1","2"], // 1
|