tgebarowski / SwiftySettings

SwiftySettings is a Swift library for building and presenting in app settings.
MIT License
53 stars 11 forks source link

Closing SwiftySettings ? #11

Open jmcazaux opened 7 years ago

jmcazaux commented 7 years ago

Hi Tomasz,

I tried to integrate SwifySettings to my app and made a few changes to improve UI (will submit a PR).

In my UI, the user accesses the settings from an app menu, then they lan on the SwiftySettings controller...

Then I did not find a way to bring them back to the app (dismiss the settings controller).

How would you achieve this?

tgebarowski commented 7 years ago

Hi,

I am not sure what kind of navigation stack you are using, but if you have a sliding menu or tab bar it shouldn't be a problem to dismiss settings view controller. Otherwise, you would have to hook up a custom button to SwiftySettingsController which would dismiss the controller. Unfortunatelly this is not currently supported out of box, but you may achieve something similar by embedding SwiftySettingsViewController in another ViewController which provides such a button.

hintoz commented 7 years ago

Hi @jmcazaux, I used this code: (viewControllers.first as? UINavigationController)?.navigationBar.items?.first?.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(dismissVC))

iballan commented 6 years ago

@hintoz Wish i found your answer couple of hours ago ! I was trying to add the button to leftBarButtonItem with no hope. Now it worked when I added to the rightBarButtonItem

xzhub commented 6 years ago

@hintoz @iballan I'm new to iOS programming, where should I put this line to dismiss the setting view?

(viewControllers.first as? UINavigationController)?.navigationBar.items?.first?.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(dismissVC))
hintoz commented 6 years ago

@xzhub In the viewDidLoad method for example.

xzhub commented 6 years ago

Thanks, now it works! For newbies like me, please note that you have to add the dismissVC function in ViewController as well.

class ViewController: SwiftySettingsViewController {

    var storage = Storage()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        loadSettingsTopDown()
        (viewControllers.first as? UINavigationController)?.navigationBar.items?.first?.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(dismissVC))
    }

    @IBAction func dismissVC(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }

... ...