Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a textfield to popup and save function? #136

Closed
SupernovasGhost opened this issue May 1, 2017 · 3 comments
Closed

Adding a textfield to popup and save function? #136

SupernovasGhost opened this issue May 1, 2017 · 3 comments
Labels

Comments

@SupernovasGhost
Copy link

I was using your pop up effect on a project I was working on and couldn't figure out how to input a textfield properly in the pop up. I was wondering if you could help me with a problem. I'd really appreciate it!

I'm using separate view controller to pull up a pop up that the user can comment in. Right now I have the text field IBAction in a separate swift file aside from the table cell view controller im working on.

I basically want to know how to turn this into your version using a separate view controller:

@IBAction func showCustomDialogTapped(_ sender: UIBarButtonItem) {

        let alertController = UIAlertController(title: "Add A Note", message: "(Note Title)", preferredStyle: .alert)
        
        alertController.addTextField { (nameTextField) in
            
            nameTextField.placeholder = "Name"
            self.nameTextField = nameTextField
        }
        
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
        }
        
        let saveAction = UIAlertAction(title: "Save", style: .default) { (action) in
            //Alert saying the user didn't type anything
            if self.nameTextField.text != "" {
                
                self.createNotesList()
                
            } else {
                //Shows a message after trying to save without text
                KRProgressHUD.showWarning(message: "Name is empty")
            } //ends here
            
        }
    
        alertController.addAction(cancelAction)
        alertController.addAction(saveAction)
        
        self.present(alertController, animated: true, completion: nil)
        }



Right now I have this, which creates the pop up view controller but the doesn't allow me to save or edit functions in the text field created in the other view controller.

@IBAction func showCustomDialogTapped(_ sender: UIBarButtonItem) {

    showCustomDialog()

}

    func showCustomDialog(animated: Bool = true) {

        // Create a custom view controller

        let notesVC = AllNotesPopUpViewController(nibName: "AllNotesPopUpView", bundle: nil)

        // Create the dialog

        let popup = PopupDialog(viewController: notesVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)

        // Create first button

        let buttonOne = CancelButton(title: "CANCEL", height: 60) {

        }

        // Create second button

        let buttonTwo = DefaultButton(title: "SAVE", height: 60) {

        }

        // Add buttons to dialog

        popup.addButtons([buttonOne, buttonTwo])

        

        // Present dialog

        present(popup, animated: animated, completion: nil)

    }

I'm basically trying to create a text field in the pop up that the user can save data from.
Is there a way to create a text field in a regular pop up or does it have to be in a separate view controller pop up?
Any help would be much appreciated. Thanks in advance

@mwfire
Copy link
Member

mwfire commented May 3, 2017

Hey there,

text fields are currently not supported for the default view controller. As you said, you can definitely handle this in your custom view controller, which is more flexible in many regards.

You could for example prevent auto-dismiss for individual buttons, at initialization of the button set dismissOnTap to false.

public init(title: String,
                height: Int = 45,
                dismissOnTap: Bool = true,
                action: PopupDialogButtonAction?)

This way, you can use the action closure to trigger logic in your custom view controller. You do have a reference to it anyhow, as you pass it to popup dialog at initialization time. Once your custom view controller logic is done and valid, you can dismiss the dialog manually, either from the button action or the custom view controller itself. You can also add a reference to the popup dialog instance to your custom view controller, just make sure it is weak so you don't have any retain cycles.

There is a similar demo to be found at #87.

Hope that helps :)

@mwfire mwfire added the question label May 3, 2017
@SupernovasGhost
Copy link
Author

Ok thanks. This is one of my fav libraries for pop up animation. Would be great to eventually see text fields supported

@mwfire
Copy link
Member

mwfire commented Sep 30, 2017

As custom view controllers can be used to achieve this behavior, there are currently no plans in adding this. Feel free to do a PR if you have a generic way of implementing this. Thx!

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

No branches or pull requests

2 participants