This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVC_Classe.swift
130 lines (94 loc) · 4.45 KB
/
VC_Classe.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import UIKit
class VC_Classe: UIViewController, UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate {
var classeListe: Array<Classe> = Array<Classe>()
var loader = UIAlertView()
@IBOutlet weak var tv_classe: UITableView!
@IBOutlet weak var b_addClasse: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Mes Classe"
MesFonctions.convertButton([b_addClasse])
// getClasses()
}
override func viewWillAppear(animated: Bool) {
classeListe.removeAll(keepCapacity: true)
getClasses()
tv_classe.reloadData()
}
//MARK: Table view implementation
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 35
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return classeListe.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return classeListe[section].listeEleve.count
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell: TVC_CustomSection = tableView.dequeueReusableCellWithIdentifier("cellSection") as! TVC_CustomSection
cell.l_title.text = classeListe[section].nom
cell.nbRow.text = String(classeListe[section].listeEleve.count)
cell.section.tag = section
return cell
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("eleve") as! UITableViewCell
cell.textLabel?.text = classeListe[indexPath.section].listeEleve[indexPath.row].nom
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(indexPath)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Api Rest Request
internal func getClasses(){
let url = NSURL(string: Constants.UrlApi + "/classe")!
var request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
var response: NSURLResponse?
var error: NSError?
let data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
if let inputData = data as NSData? {
println(inputData)
let jsonResult = MesFonctions.parseJSON(inputData)
var classes = jsonResult["classe"] as! NSArray
for array in classes {
let dico = array as! NSDictionary
var classe = Classe(classe: dico)
classe.APIgetEleves()
self.classeListe.append(classe)
}
}
}
internal func getLoader(){
loader = UIAlertView(title: "Loading", message: "Please wait...", delegate: nil, cancelButtonTitle: nil);
var loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(50, 10, 37, 37)) as UIActivityIndicatorView
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.startAnimating();
loader.setValue(loadingIndicator, forKey: "accessoryView")
loadingIndicator.startAnimating()
loader.show()
}
// MARK: - Navigation
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
if let VC = segue!.destinationViewController as? VC_ClasseDetail {
if let bt_section = sender as? UIButton {
VC.indexOfClasse = bt_section.tag
VC.classeListe = self.classeListe
}
}
if let VC = segue!.destinationViewController as? VC_Eleves {
if let indexPath = tv_classe.indexPathForSelectedRow() as NSIndexPath? {
VC.classe = classeListe[indexPath.section]
VC.indexOfClasse = indexPath.section
VC.indexOfEleve = indexPath.row
}
}
}
}