-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterTableViewController.swift
More file actions
154 lines (93 loc) · 4.45 KB
/
MasterTableViewController.swift
File metadata and controls
154 lines (93 loc) · 4.45 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// MasterTableViewController.swift
// FlyDubai
//
// Created by Aiman Abdullah Anees on 09/07/16.
// Copyright © 2016 Aiman Abdullah Anees. All rights reserved.
//
import UIKit
import CoreLocation
import SwiftyJSON
import Alamofire
import CoreData
var City:String = ""
class MasterTableViewController: UITableViewController,CLLocationManagerDelegate{
@IBOutlet var Label: UILabel!
var TitleArray = ["About","Helpline","Explore","Offers"]
var ImageArray = ["p10","p7","3","4"]
var AllInfoArray = [String]()
let LocationManager = CLLocationManager()
var LocationLabel:String = ""
override func viewDidLoad() {
super.viewDidLoad()
self.LocationManager.delegate = self
self.LocationManager.desiredAccuracy = kCLLocationAccuracyBest
self.LocationManager.requestWhenInUseAuthorization()
self.LocationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
CLGeocoder().reverseGeocodeLocation(manager.location!) { (placemarks, error) in
if error != nil{
print("Error: "+(error?.localizedDescription)!)
return
}
if placemarks?.count>0
{
let pm = placemarks![0] as! CLPlacemark
self.displayLocationInfo(pm)
}
}
}
func displayLocationInfo(placemark:CLPlacemark)
{
AllInfoArray = []
self.LocationManager.stopUpdatingLocation()
print(placemark.locality)
print(placemark.administrativeArea)
print(placemark.country)
City = placemark.locality!
self.LocationLabel = placemark.locality!
Label.text = "Welcome to \(City)"
let path :String = NSBundle.mainBundle().pathForResource("FlyDubai", ofType: "json")!
let jsonData = NSData(contentsOfFile: path)
let readableJSON = JSON(data: jsonData!, options: NSJSONReadingOptions.MutableContainers, error: nil)
for i in 1...3
{
var city = "City"
city += "\(i)"
if(readableJSON["FlyDubai"][city]["name"].string == City)
{
AllInfoArray.append(readableJSON["FlyDubai"][city]["about"].string!)
AllInfoArray.append(readableJSON["FlyDubai"][city]["helpline"].string!)
AllInfoArray.append(readableJSON["FlyDubai"][city]["explore"].string!)
AllInfoArray.append(readableJSON["FlyDubai"][city]["offers"].string!)
}
}
}
func locationManager(manager: CLLocationManager,didFailWithError error: NSError)
{
print("Error: "+error.localizedDescription)
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return TitleArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let ImageView = cell.viewWithTag(1) as! UIImageView
ImageView.image = UIImage(named: ImageArray[indexPath.row])
var TextLabel = cell.viewWithTag(2) as! UILabel
TextLabel.text = TitleArray[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let TextSelected = TitleArray[indexPath.row]
var DetailVC:DetaitViewController = self.storyboard?.instantiateViewControllerWithIdentifier("DetaitViewController") as! DetaitViewController
DetailVC.Description = AllInfoArray[indexPath.row]
self.presentViewController(DetailVC, animated: true, completion: nil)
}
}