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 · 25 comments

Comments

@liufengyu
Copy link

commented Jul 1, 2016

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

@hackiftekhar

This comment has been minimized.

Copy link
Owner

commented Jul 1, 2016

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

@liufengyu

This comment has been minimized.

Copy link
Author

commented Jul 1, 2016

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

@hackiftekhar

This comment has been minimized.

Copy link
Owner

commented Jul 1, 2016

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2016

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

This comment has been minimized.

Copy link

commented Jul 4, 2016

@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

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2016

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

This comment has been minimized.

Copy link

commented Jul 4, 2016

@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

This comment has been minimized.

Copy link

commented Jul 6, 2016

@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

This comment has been minimized.

Copy link
Owner

commented Jul 6, 2016

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Owner

commented Jul 7, 2016

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

This comment has been minimized.

Copy link

commented Jul 7, 2016

@hackiftekhar ah! That works! Thanks :D

@viral105

This comment has been minimized.

Copy link

commented Jul 15, 2016

What to do in objective c for same problem ?

@hackiftekhar

This comment has been minimized.

Copy link
Owner

commented Jul 15, 2016

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

@viral105

This comment has been minimized.

Copy link

commented Jul 25, 2016

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

This comment has been minimized.

Copy link
Owner

commented Jul 25, 2016

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

@viral105

This comment has been minimized.

Copy link

commented Jul 27, 2016

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

@hackiftekhar

This comment has been minimized.

Copy link
Owner

commented Jul 27, 2016

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

@oliverfoggin

This comment has been minimized.

Copy link

commented Jul 27, 2016

@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

This comment has been minimized.

Copy link

commented Jul 27, 2016

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

@kumardiwa

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Owner

commented Aug 3, 2017

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

@xeieshan

This comment has been minimized.

Copy link

commented Oct 22, 2017

overrideIteratingTextFields works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.