Skip to content

Commit a0ade9e

Browse files
committed
Remove boolean for activity indicator
1 parent cfca241 commit a0ade9e

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

TCAT/Controllers/AllStopsTableViewController.swift

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class AllStopsTableViewController: UITableViewController {
2121
var unwindAllStopsTVCDelegate: UnwindAllStopsTVCDelegate?
2222
var height: CGFloat?
2323
var currentChar: Character?
24-
var showActivityIndicator = false
25-
var activityIndicator: UIActivityIndicatorView!
24+
var activityIndicator: UIActivityIndicatorView?
2625

2726
override func viewWillLayoutSubviews() {
2827
if let y = navigationController?.navigationBar.frame.maxY {
@@ -57,8 +56,6 @@ class AllStopsTableViewController: UITableViewController {
5756
tableView.tableFooterView = UIView()
5857
// Set top of table view to align with scroll view
5958
tableView.contentOffset = .zero
60-
61-
setUpActivityIndicator()
6259
}
6360

6461
// MARK: TableView DataSource
@@ -194,25 +191,23 @@ class AllStopsTableViewController: UITableViewController {
194191

195192
// MARK: DZNEmptyDataSet
196193
extension AllStopsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
197-
198194
func setUpActivityIndicator() {
199195
activityIndicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
200-
view.addSubview(activityIndicator!)
201-
activityIndicator.snp.makeConstraints { (make) in
202-
make.centerX.equalToSuperview()
203-
make.centerY.equalToSuperview()
196+
if let activityIndicator = activityIndicator {
197+
view.addSubview(activityIndicator)
198+
activityIndicator.snp.makeConstraints { (make) in
199+
make.centerX.equalToSuperview()
200+
make.centerY.equalToSuperview()
201+
}
204202
}
205203
}
206204

207205
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
208-
if showActivityIndicator {
209-
return nil
210-
}
211-
return #imageLiteral(resourceName: "emptyPin")
206+
return activityIndicator != nil ? nil : #imageLiteral(resourceName: "emptyPin")
212207
}
213208

214209
func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
215-
if showActivityIndicator {
210+
if let _ = activityIndicator {
216211
return nil
217212
}
218213
let title = "Couldn't Get Stops"
@@ -221,7 +216,7 @@ extension AllStopsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDel
221216
}
222217

223218
func buttonTitle(forEmptyDataSet scrollView: UIScrollView!, for state: UIControl.State) -> NSAttributedString! {
224-
if showActivityIndicator {
219+
if let _ = activityIndicator {
225220
return nil
226221
}
227222
let title = "Retry"
@@ -230,14 +225,16 @@ extension AllStopsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDel
230225
}
231226

232227
func emptyDataSet(_ scrollView: UIScrollView!, didTap didTapButton: UIButton!) {
233-
showActivityIndicator = true
234-
tableView.reloadData()
235228
setUpActivityIndicator()
236-
activityIndicator.startAnimating()
237-
238-
retryNetwork {() -> Void in
229+
if let activityIndicator = activityIndicator {
230+
tableView.reloadData()
231+
activityIndicator.startAnimating()
232+
}
233+
retryNetwork { () -> Void in
239234
self.setUpTableOnRetry()
240-
self.activityIndicator.stopAnimating()
235+
if let activityIndicator = self.activityIndicator {
236+
activityIndicator.stopAnimating()
237+
}
241238
}
242239
}
243240

0 commit comments

Comments
 (0)