Moving keyboard text fields using TPKeyboardAvoidingScrollView not working

I have a TabBar application with one of its tabs built into the NavigationController. This particular view is a form with text fields on it. I want TPKeyboardAvoidingScrollView to move UITextFields up when the keyboard goes into view mode. I followed the instructions on the Github page, but it just doesn't work.

This is what I did according to the instructions:

  • Added TPKeyboardAvoidingScrollView.h and .m to my project
  • Added UIScrollView to the storyboard view (Xcode 4.3.1)
  • Selected ScrollView and inspector changed his class to TPKeyboardAvoidingScrollView
  • Moved all my text fields to UIScrollView

This did not work ... Therefore, looking at the sample code, I tried to add a few more things:

  • In my view, the controllers for the .h file I added:

    @class TPKeyboardAvoidingScrollView;

  • and linked ScrollView, as a result of which this line of added code was added:

    @property (weak, non-atomic) IBOutlet TPKeyboardAvoidingScrollView * scrollView;

  • Imported TPKeyboardAvoidingScrollView.h file to .m file. my controllers.

But still, the input code that everyone else seems to be praising doesn't work for me.

Can anyone point out my incompetence, please? Thanks in advance for any help you can provide ...

+4
source share
2 answers

I ran into this exact problem when trying to use this class, and spent a lot of time on something that should be time-saving.

I set breakpoints inside TPKeyboardAvoidingScrollView and noticed that none of them ever hit. After several attempts, I noticed some results in the debug window:
"Unknown class TPKeyboardAvoidingScrollView in Interface Builder file" error at runtime

I found useful information in this thread . It basically seemed like the file was optimized because it was never used in code anywhere.

To make it work again, I did a couple of things, any or all of which may be necessary:

  • Click on the TPKeyboardAvoidingScrollView classes in the project outline. Find out the Utilities panel on the right side in Xcode if you have it hidden, and make sure that the files actually have a specific target membership or that they won't be created.
  • Remove the application from the device or simulator on which you are testing to get a new load.
  • Restore the project and download it to the device / simulator. The error should be removed, you should be able to hit breakpoints in the TPKeyboardAvoidingScrollView classes, and now everything should work.

Alternatively, you can look at the solution provided by jhoule here . The bottom line is that you are adding a call:
[TPKeyboardAvoidingScrollView class];
for your application delegate or elsewhere in your code to make sure the code receives the link and is not optimized.

Hope this helps.

+6
source

what you need to do is go to the main storyboard and add the missing restrictions in viewing the scroll, or you can click on the scroll screen on the storyboard and go to the editor at the top of the xcode menu and go to solve auto-detection problems and press reset on the proposed restrictions . Run the project. Good luck.

0
source

Source: https://habr.com/ru/post/1402785/


All Articles