質問編集履歴
3
こード記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
サンプルでは、2種類のmp3データを使い回して試しています。(ファイル名は1.mp3、2.mp3)
|
46
46
|
|
47
|
-
サンプルでは、tableViewのセルから画面遷移して遷移先のページから音の再生やページスクロール
|
47
|
+
サンプルでは、tableViewのセルから画面遷移して遷移先のページから音の再生やページスクロールする仕様にしています。
|
48
48
|
|
49
49
|
```
|
50
50
|
|
2
コード記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -305,219 +305,3 @@
|
|
305
305
|
}
|
306
306
|
|
307
307
|
```
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
###その他のソースコード(ページングするためのViewControllerとPageViewController)
|
312
|
-
|
313
|
-
```
|
314
|
-
|
315
|
-
import UIKit
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
class PageViewController: UIPageViewController, UIPageViewControllerDataSource {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
var selectedIndex: Int = 0 // タップされたセルのindex
|
324
|
-
|
325
|
-
var pageIndex:Int = 0 // 各ページに割り当てたindex
|
326
|
-
|
327
|
-
var contentVCs = [UIViewController]()
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
override func viewDidLoad() {
|
332
|
-
|
333
|
-
super.viewDidLoad()
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
// ナビゲーションバーの透過を無効にする。
|
338
|
-
|
339
|
-
self.navigationController!.navigationBar.isTranslucent = false
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
dataSource = self
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
for index in 0..<20 {
|
348
|
-
|
349
|
-
let contentVC = storyboard?.instantiateViewController(withIdentifier: "PageContentViewController") as! PageContentViewController
|
350
|
-
|
351
|
-
contentVC.pageIndex = index
|
352
|
-
|
353
|
-
contentVCs.append(contentVC)
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
self.setViewControllers([contentVCs[selectedIndex]], direction: .forward, animated: true, completion: nil)
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
} // viewDidLoad()を閉じる
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
// MARK: - UIPageViewControllerDataSource
|
370
|
-
|
371
|
-
// スワイプでページを戻る(Before)
|
372
|
-
|
373
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
374
|
-
|
375
|
-
guard let index = contentVCs.index(of: viewController as! PageContentViewController), index > 0 else {
|
376
|
-
|
377
|
-
return nil
|
378
|
-
|
379
|
-
}
|
380
|
-
|
381
|
-
let previousVC = contentVCs[index - 1]
|
382
|
-
|
383
|
-
return previousVC
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
// スワイプでページを進む(After)
|
390
|
-
|
391
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
392
|
-
|
393
|
-
guard let index = contentVCs.index(of: viewController as! PageContentViewController), index < contentVCs.count - 1 else {
|
394
|
-
|
395
|
-
return nil
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
let nextVC = contentVCs[index + 1]
|
400
|
-
|
401
|
-
return nextVC
|
402
|
-
|
403
|
-
}
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
}
|
408
|
-
|
409
|
-
```
|
410
|
-
|
411
|
-
```
|
412
|
-
|
413
|
-
import UIKit
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
let sectionTitle = ["Title"] //セクションに表示するデータ
|
422
|
-
|
423
|
-
let section0 = Array(1...20) //セルに表示するデータ
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
@IBOutlet weak var tableView: UITableView!
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
override func viewDidLoad() {
|
432
|
-
|
433
|
-
super.viewDidLoad()
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
tableView.delegate = self
|
438
|
-
|
439
|
-
tableView.dataSource = self
|
440
|
-
|
441
|
-
}
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
override func didReceiveMemoryWarning() {
|
446
|
-
|
447
|
-
super.didReceiveMemoryWarning()
|
448
|
-
|
449
|
-
}
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
func numberOfSections(in tableView: UITableView) -> Int {
|
454
|
-
|
455
|
-
return sectionTitle.count
|
456
|
-
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
462
|
-
|
463
|
-
return section0.count
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
470
|
-
|
471
|
-
return sectionTitle[section]
|
472
|
-
|
473
|
-
}
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
478
|
-
|
479
|
-
return 30
|
480
|
-
|
481
|
-
}
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
486
|
-
|
487
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
488
|
-
|
489
|
-
cell.textLabel?.text = "(section0[indexPath.row])"
|
490
|
-
|
491
|
-
return cell
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
498
|
-
|
499
|
-
if segue.identifier == "ToPageViewController" {
|
500
|
-
|
501
|
-
if let indexPath = self.tableView.indexPathForSelectedRow {
|
502
|
-
|
503
|
-
tableView.deselectRow(at: indexPath, animated: false)
|
504
|
-
|
505
|
-
if let pageViewController = segue.destination as? PageViewController {
|
506
|
-
|
507
|
-
pageViewController.selectedIndex = indexPath.row
|
508
|
-
|
509
|
-
}
|
510
|
-
|
511
|
-
}
|
512
|
-
|
513
|
-
}
|
514
|
-
|
515
|
-
}
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
}
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
```
|
1
コード記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
-
class PageContentViewController: UIViewController,
|
59
|
+
class PageContentViewController: UIViewController, AVAudioPlayerDelegate {
|
60
60
|
|
61
61
|
|
62
62
|
|