Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Can't close modally presented ViewController any more #10

Closed
apm-lucas-zacharias opened this issue Jun 4, 2016 · 8 comments
Closed

Comments

@apm-lucas-zacharias
Copy link

apm-lucas-zacharias commented Jun 4, 2016

Until now I have used STLocationRequest in a "normal" ViewController.
The only thing I changed was presenting the VC modally but now I can't close the VC itself anymore after showing the LocationRequest.

I use
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
for closing and it's working everywhere fine but not in the VC with the LocationRequest...

@SvenTiigi
Copy link
Owner

Hey LucasZL,

there is no need to dismiss the STLocationRequestController manually. The STLocationRequestController will dismiss itself when the user tapped the NotNow-Button or accepted or denied the location request.

So please give me a code sample how you call the STLocationRequest Screen.

Preferred way in Swift, is to use the UIViewController Extension:

import STLocationRequest

func showLocationRequest(){
    self.showLocationRequestController(
                        setTitle: "We need your location for some awesome features",
                        setAllowButtonTitle: "Alright",
                        setNotNowButtonTitle: "Not now",
                        setMapViewAlphaValue: 0.9,
                        setBackgroundViewColor: UIColor.lightGrayColor(),
                        setDelegate: self)
}

Also don't forget to apply to the LocationRequestDelegate if you want to get notified about different states of the STLocationRequestController

@apm-lucas-zacharias
Copy link
Author

I know thats working fine. Im talking about the VC thats calling showLocationRequest(). I can't close it after showing LocationRequest

@SvenTiigi
Copy link
Owner

Got it!

So it might be the best to give me a code sample of how you present your ViewController and the code inside the ViewController to fix that problem.
But it seems thats it is not combined with the STLocationRequestController cause it's presenting itself modally where it got called and so it's not changing anything from ViewController where you call the STLocationRequestController. The first thing I would check is if your ViewController is presented modally and it's NOT presented by a show or push segue.

@apm-lucas-zacharias
Copy link
Author

I present the VC modally:
screen shot 2016-06-04 at 17 17 30

and then call
self.showLocationRequestController( setTitle: NSLocalizedString("REQUEST_LOCATION_TITLE", comment: "We need your location for some awesome features"), setAllowButtonTitle: NSLocalizedString("ALRIGHT", comment: "alright"), setNotNowButtonTitle: NSLocalizedString("NOT_NOW", comment: "not now"), setMapViewAlphaValue: 0.9, setBackgroundViewColor: UIColor.lightGrayColor(), setDelegate: self)
and then use
@IBAction func closeClicked(sender: AnyObject) { self.navigationController?.dismissViewControllerAnimated(true, completion: nil) }

to close the VC.

It's working fine if I don't call self.showLocationRequestController and just call locationManager.requestWhenInUseAuthorization()

@SvenTiigi
Copy link
Owner

Do you have embedded your ViewController which will be presented modally as you written in a UINavigationController? If not please change your closeClicked function from

@IBAction func closeClicked(sender: AnyObject) {
    self.navigationController?.dismissViewControllerAnimated(true, completion: nil) 
}

to

@IBAction func closeClicked(sender: AnyObject) {
    self.dismissViewControllerAnimated(true, completion: nil) 
}

@apm-lucas-zacharias
Copy link
Author

Yes I have

@SvenTiigi
Copy link
Owner

SvenTiigi commented Jun 4, 2016

So I tried to reproduce your problem in a new Xcode project and there is no problem by presenting a viewcontroller modally and on that viewcontroller call self.showLocationRequestController() and dismiss it by a IBAction func with self.dismissViewControllerAnimated() with no UINavigationController and self.navigationController?.dismissViewControllerAnimated() with an UINavigationController.
bildschirmfoto 2016-06-04 um 17 45 56
bildschirmfoto 2016-06-04 um 17 46 04
bildschirmfoto 2016-06-04 um 17 46 20

Also you might tried to debug it and also before calling self.navigationController?.dismissViewControllerAnimated() print out your navigationController to check if its not nil print(self.navigationController)

So to give further help please provide the code inside your ViewController to have look what might causes that problem.

@SvenTiigi
Copy link
Owner

SvenTiigi commented Jun 25, 2016

@LucasZL is your request still a current problem or did you found a solution for your problem?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants