Skip to content

Commit

Permalink
-Fixed app delegate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Esqarrouth authored and Goktug Yilmaz committed Nov 23, 2015
1 parent c7a1596 commit 2ba85ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
22 changes: 12 additions & 10 deletions EZLoadingActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ struct EZLoadingActivity {
return false
}

guard topMostController != nil else {
print("EZLoadingActivity Error: You don't have any views set. You may be calling them in viewDidLoad. Try viewDidAppear instead.")
return false
}

instance = LoadingActivity(text: text, disableUI: disableUI)
return true
}
Expand Down Expand Up @@ -120,7 +125,7 @@ struct EZLoadingActivity {
addSubview(activityView)
addSubview(textLabel)

UIApplication.topMostController().view.addSubview(self)
topMostController!.view.addSubview(self)

if disableUI {
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
Expand Down Expand Up @@ -248,15 +253,12 @@ private extension UIScreen {
}
}

private extension UIApplication {
class func topMostController() -> UIViewController {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var topController = appDelegate.window!.rootViewController

while topController?.presentedViewController != nil {
topController = topController?.presentedViewController
}
return topController!
private var topMostController: UIViewController? {
var presentedVC = UIApplication.sharedApplication().keyWindow?.rootViewController
while let pVC = presentedVC?.presentedViewController {
presentedVC = pVC
}

return presentedVC
}

6 changes: 5 additions & 1 deletion EZLoadingActivity/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

EZLoadingActivity.showWithDelay("Testing..", disableUI: false, seconds: 3)
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
EZLoadingActivity.showWithDelay("Testing..", disableUI: false, seconds: 3)

}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
Expand Down

0 comments on commit 2ba85ba

Please sign in to comment.