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

TextField Previous and Next not appear #549

Closed
liufengyu opened this issue Jul 1, 2016 · 26 comments
Closed

TextField Previous and Next not appear #549

liufengyu opened this issue Jul 1, 2016 · 26 comments
Labels

Comments

@liufengyu
Copy link

on ViewController when I add TextField to a subView of self.view

@hackiftekhar
Copy link
Owner

Prev Next will appear if there are more than 1 sibling textField

@liufengyu
Copy link
Author

liufengyu commented Jul 1, 2016

I add 3 textField but not appear, when add to self.view they appeared

@hackiftekhar
Copy link
Owner

You added 3 textField but doesn't appear? when you added to self.view they appeared? didn't understand. Both are looking like same statement.

@oliverfoggin
Copy link

oliverfoggin commented Jul 1, 2016

Is there any way to get IQKeyboardManager to search up and down the view hierarchy? I have a view laid out with multiple nested UIStackViews (a common use case for stack views) and I can't find a way to get the next rev to appear.

Would be awesome to have a way of manually setting them like a delegate callback "nextTextFieldForCurrentTextField" etc...

Or even just an array of text fields for the manager to iterate through.

IQKeyboardManager.sharedManager() = [firstTextField, secondTextField]

Etc...

If you can point me in the right direction in the project I'd be happy to update it and make a pull request.

@oliverfoggin
Copy link

oliverfoggin commented Jul 4, 2016

I added a couple lines of code... not in a PR yet but possibly soon.

Anyway...

///------------------
/// MARK: AutoToolbar
///------------------

/** Get all UITextField/UITextView siblings of textFieldView. */
private func responderViews()-> [UIView]? {

    if let overriddenTextFields = overrideIteratingTextFields {
        return overriddenTextFields
    }
    ... rest of the method...

and a new property...

public var overrideIteratingTextFields: [UIView]?

And all I need to do is...

    IQKeyboardManager.sharedManager().overrideIteratingTextFields = [
        nameField,
        cardNumberField,
        expiryDateField,
        cvvField
    ]

and it works fine. Just need to set it back to nil in viewWillDisappear

@liufengyu you may be able to use the same thing here to force the next/prev buttons to appear.

@hackiftekhar
Copy link
Owner

That's a bit of extra manual management and need to take extra care in viewWillDisappear. This is not we want in a library, @oliverfoggin We may need to come with a generic solution which should do the trick without any external textField references.

@oliverfoggin
Copy link

@hackiftekhar true. But in this case the automatic part of the library isn't working. You could make it recursively search for all UITextFields but not sure how that would perform (also a possibility of getting text fields that currently aren't visible etc...)

This was a quick hack for me and works until something better is done.

@hackiftekhar
Copy link
Owner

Yeah you totally correct It's a quick hack this is why it's not suitable for a open source library used by many developers. We may need to come up with a generic solution by combining toolbarManageBehaviour with IQPreviousNextView.

@oliverfoggin
Copy link

@hackiftekhar I didn't say it was suitable. I merely pointed out how I had forced it to work. I had 20 minutes to get this working. I wouldn't have submitted this but something similar. Anyway, it is working for me now and if I remove the update then it doesn't work so I'm happy. Do whatever you think is necessary.

@oliverfoggin
Copy link

@hackiftekhar please could you explain what the toolbarPreviousNextAllowedClasses property does?

I have added this...

    IQKeyboardManager.sharedManager().toolbarPreviousNextAllowedClasses = [UIStackView.self, UIView.self]

But it is still not showing prev or next arrows.

Going to have to put my hack in again to fix this. Thanks

@hackiftekhar
Copy link
Owner

This property treats all it's inner subviews as part of siblings to navigate through. I'm not sure why it doesn't work for you.

@oliverfoggin
Copy link

oliverfoggin commented Jul 7, 2016

@hackiftekhar I think the problem (possibly) is that it only goes one level deep.

My view hierarchy is...

UIStackView
    -UIStackView
        -UITextField
    -UIStackView
        -UITextField

So it would need to go up twice and down twice to find the next/prev text field.

It's actually more complex than this but it shows as an example.

As much as I'd love for there to be an automatic way to solve this I think it would be much easier to add a manual method to override it like my example above.

@hackiftekhar
Copy link
Owner

ok, I think you should put all this hierarchy inside IQPreviousNextView (On top of the most top UIStackView), so it will find all inner textFields.

@oliverfoggin
Copy link

@hackiftekhar ah! That works! Thanks :D

@viral105
Copy link

What to do in objective c for same problem ?

@hackiftekhar
Copy link
Owner

Things are same for ObjC and Swift, so you can follow same approach in both languages.

@viral105
Copy link

Thanks for reply.
I have tried following in objective c.
[IQKeyboardManager sharedManager] = [tfd1,tfd2,tfd3,tfd4];

but it is giving me following error.
Expected Identifier.

@hackiftekhar
Copy link
Owner

@viral105 please check solution regarding IQPreviousNextView. You are currently doing wrong.

@viral105
Copy link

@hackiftekhar I am not using UIStackView but my textfields are subview of different UIView. So where should I found the code for that ?

@hackiftekhar
Copy link
Owner

You could check CustomView Example in demo or you can read documentation here:-
https://github.com/hackiftekhar/IQKeyboardManager/blob/master/MANUAL%20MANAGEMENT.md

@oliverfoggin
Copy link

@viral105 the solution (that was mentioned long ago) is to use the IQPreviousNextView and put all your text fields inside that.

This is a very easy solution and works.

I'm not even sure what your code... [IQKeyboardManager sharedManager] = [tfd1,tfd2,tfd3,tfd4]; is trying to do? What do you think it is doing?

Just put the controls inside the IQPreviousNextView.

@viral105
Copy link

Its Done. @oliverfoggin comment helped me to resolve my problem.
Thanks @oliverfoggin and @hackiftekhar for your time and help.

@kumardiwa
Copy link

kumardiwa commented Jul 21, 2017

I've 5 textFileds in a single StackView and previous and next button is not working. Although I've written IQKeyboardManager.sharedManager().previousNextDisplayMode = .alwaysShow in viewWillApear but still not working.

@hackiftekhar
Copy link
Owner

Your all textField might not be in same superview I think?

@xeieshan
Copy link

xeieshan commented Oct 22, 2017

overrideIteratingTextFields works for me.

@Bergasms
Copy link

I'm curious why the Author thinks embedding views in a IQPreviousNextView is not considered too much manual work but sticking references in an array is considered too much manual work. For a library presenting itself as automatic i think buggering around with classes in a storyboard is more invasive and prone to future problems than handling a manual override in your code. It's certainly easier to remove the code based condition and the compiler will catch problems for you at that level. Putting custom things in a storyboard is a great way to give someone a runtime crash in the future and you also cannot document it for anyone coming past making changes to the code.

@oliverfoggin presents a really simple solution that will work for any sort of complicated layout where you have the references available, and in 99% of the cases you will have the references available because input fields without references are not super useful.

Regardless, the IQPreviousNextView solution does work, but now I have had to pollute one of our libraries with another dependency just to add it into the storyboard, and write a note explaining the footgun that's now hidden in one of the libraries in an inobvious way that the compiler won't catch.

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

7 participants