This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourseViewController.swift
84 lines (58 loc) · 2.84 KB
/
CourseViewController.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// CourseViewController.swift
// GradeCoach
//
// Created by Connor Wybranowski on 4/26/15.
// Copyright (c) 2015 Wybro. All rights reserved.
//
import UIKit
class CourseViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var courseName: UILabel!
@IBOutlet weak var courseGoal: UILabel!
@IBOutlet weak var courseWorkTableView: UITableView!
var selectedCourseName: String?
var selectedCourseGoal: String?
var selectedCourseIndex: NSIndexPath!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
courseName.text = selectedCourseName
courseGoal.text = selectedCourseGoal
}
override func viewDidAppear(animated: Bool) {
courseWorkTableView.reloadData()
// println(courseMgr.getCourseWork(selectedCourseIndex.row).count)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete){
// println("Before: " + "\(courseMgr.courses.count)")
tableView.beginUpdates()
courseMgr.removeCourseWork(selectedCourseIndex, courseWorkIndex: indexPath)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Left)
tableView.endUpdates()
}
// println("After: " + "\(courseMgr.courses.count)")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return courseMgr.getCourseWork(selectedCourseIndex.row).count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CourseItem", forIndexPath: indexPath) as! CourseWorkTableViewCell
cell.courseWorkTitle.text = courseMgr.getCourseWorkItems(selectedCourseIndex.row, courseWorkIndex: indexPath.row).type
cell.courseWorkWeight.text = "\(courseMgr.getCourseWorkItems(selectedCourseIndex.row, courseWorkIndex: indexPath.row).weight)" + "%"
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "newCourseWork"{
var DestViewController = segue.destinationViewController as! newCourseWorkViewController
DestViewController.courseIndex = selectedCourseIndex
}
}
}