forked from MartiSK/Team16EME185
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainTableViewController.swift
executable file
·67 lines (50 loc) · 2.51 KB
/
MainTableViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// MainTableViewController.swift
// ChatterApp2.0
//
// Created by David Carter on 3/26/15.
// Copyright (c) 2015 Team16. All rights reserved.
//
import UIKit
import AVFoundation
import CoreData
class MainTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var audioPlayer = AVAudioPlayer()
var chatterFiles: [ChatterFile] = []
override func viewDidLoad() {
super.viewDidLoad()
// Roll Tide...
self.tableView.dataSource = self
self.tableView.delegate = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Roll Tide...
var context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext!
var request = NSFetchRequest(entityName: "ChatterFile")
self.chatterFiles = context.executeFetchRequest(request, error: nil)! as! [ChatterFile]
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.chatterFiles.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var chatterfile = self.chatterFiles[indexPath.row]
var cell = UITableViewCell()
cell.textLabel!.text = chatterfile.name
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var chatterfile = self.chatterFiles[indexPath.row]
var baseString : String = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! String
var pathComponents = [baseString, chatterfile.url]
var audioNSURL = NSURL.fileURLWithPathComponents(pathComponents)
self.audioPlayer = AVAudioPlayer(contentsOfURL: audioNSURL, error: nil)
self.audioPlayer.play()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var nextViewControler = segue.destinationViewController as! ChatterFileViewController
nextViewControler.previousViewController = self
}
}