-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuestMainShow.swift
178 lines (119 loc) · 6.34 KB
/
GuestMainShow.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// GuestMainShow.swift
//
//
// Created by Abdullah Jacksi on 3/25/19.
//
import UIKit
import Firebase
import SDWebImage
import DZNEmptyDataSet
class GuestMainShow: UIViewController, UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
var arrayItems = [ItemModel]()
@IBOutlet weak var GuestTableView: UITableView!
{
didSet {
GuestTableView.delegate = self ;
GuestTableView.dataSource = self ;
GuestTableView.emptyDataSetSource = self
GuestTableView.emptyDataSetDelegate = self
// GuestTableView.tableFooterView = UIView()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// for table view
GuestTableView.register(UINib(nibName: "FirstOfficeCell", bundle: nil), forCellReuseIdentifier: "myCell2")
/* ?????????????????????????????????????????????????????????????????
//MARK: get items from database
how to make the code below to function
????????????????????????????????????????????????????????????????? */
_ = Database.database().reference().child("Items").observe(DataEventType.value, with: { (snapshot) in
//if the reference have some values
if snapshot.childrenCount > 0 {
//clearing the list
self.arrayItems.removeAll()
//iterating through all the values
for Items in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
let itemObject = Items.value as? [String: AnyObject]
let TypeOfOffer = itemObject?["TypeOfOffer"]
let TypeOfSelling = itemObject?["TypeOfSelling"]
let Address = itemObject?["Address"]
let NumberOfRoom = itemObject?["NumberOfRoom"]
let NumberOfBath = itemObject?["NumberOfBath"]
let HouseArea = itemObject?["HouseArea"]
let Price = itemObject?["Price"]
let Image = itemObject?["Image"]
let ID = itemObject?["ID"]
let itemId = itemObject?["itemId"]
//creating artist object with model and fetched values
let item = ItemModel(TypeOfOffer: TypeOfOffer as! String?, TypeOfSelling: TypeOfSelling as! String?, Address: Address as! String?, NumberOfRoom: NumberOfRoom as! String? ,NumberOfBath: NumberOfBath as! String? , HouseArea: HouseArea as! String? ,Price: Price as! String?, Image: Image as! String?, ID: ID as! String?, itemId:itemId as! String? )
//appending it to list
self.arrayItems.insert(item, at: 0)
}
//reloading the tableview
DispatchQueue.main.async { [weak self] in
self?.GuestTableView.reloadData()
}
// or
// self?.myTableView.reloadData()
// or
// Threads.performTaskInMainQueue {
// self.myTableView.reloadData()
// }
}else{
print("======================== \n there is no return data because snapshot.childrenCount = 0 ")
}
})
// Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// print("raw ========= \(arrayItems[0].Address) \n\n\n")
return arrayItems.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 130
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = GuestTableView.dequeueReusableCell(withIdentifier: "myCell2") as! FirstOfficeCell
// print("cell *********** \(self.arrayItems.count) \n\n\n")
// print("Auth.auth().currentUser?.uid>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\(Auth.auth().currentUser?.uid)")
// print("arrayItems[0].ID >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\(arrayItems[0].ID)")
let item : ItemModel
item = arrayItems[indexPath.row]
//MARK: download image
if let imageDownloadURL = self.arrayItems[indexPath.row].Image {
let url = URL(string: imageDownloadURL)
let chat = UIImage(named: "bic")
cell.smallImageView.sd_setImage(with: url, placeholderImage: chat )
}
if arrayItems.count > 0 {
cell.smallTextOffer?.text = item.TypeOfOffer
cell.smallTextSelling?.text = item.TypeOfSelling
cell.smallTextAddress?.text = item.Address
cell.smallTextRoom?.text = item.NumberOfRoom
cell.smallTextPrice?.text = "$ " + item.Price!
cell.smallPlace?.text = item.HouseArea
cell.smallBath?.text = item.NumberOfBath
}
return cell
}
//MARK: to show massage when table view empty
// Add title for empty dataset
func title(forEmptyDataSet _: UIScrollView!) -> NSAttributedString! {
let str = "Hello!"
let attrs = [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: UIFont.TextStyle.headline)]
return NSAttributedString(string: str, attributes: attrs)
}
// Add description/subtitle on empty dataset
func description(forEmptyDataSet _: UIScrollView!) -> NSAttributedString! {
let str = "the table view is empty right now!!!"
let attrs = [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body)]
return NSAttributedString(string: str, attributes: attrs)
}
//Add your image
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
return UIImage(named: "map2")
}
}