4

I have a TabBar app with one of its tabs embedded in a NavigationController. This particular view is a form with text fields on it. I want to us the TPKeyboardAvoidingScrollView to move the UITextFields up when the keyboard moves into view. I have followed the instructions on the Github page but it just does not work at all.

This is what I have done as per the instructions:

  1. Added the TPKeyboardAvoidingScrollView.h and .m to my project
  2. Added a UIScrollView to the view on the storyboard (Xcode 4.3.1)
  3. Selected the ScrollView and in the inspector changed its class to TPKeyboardAvoidingScrollView
  4. Moved all my textfields into the UIScrollView

This did not work... So looking at the sample code I tried adding a few more things:

  1. In my view controllers .h file I added:

    @class TPKeyboardAvoidingScrollView;

  2. and linked the ScrollView resulting in this line of code being added:

    @property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *scrollView;

  3. Imported the TPKeyboardAvoidingScrollView.h into my controllers .m file.

But still the drop-in code that everybody else seems to praise just does not work for me.

Can anyone point out my incompetence please? Thanks in advance for any assistance you may be able to provide...

LU RD
  • 34,438
  • 5
  • 88
  • 296
Sean
  • 440
  • 1
  • 6
  • 20

2 Answers2

6

I ran into this exact problem when trying to use this class as well and spent wasted a good deal of time on something that is supposed to be a time-saver.

I set breakpoints inside the TPKeyboardAvoidingScrollView and noticed that none of them were ever hit. After trying several things I noticed some output in the debug window:
“Unknown class TPKeyboardAvoidingScrollView in Interface Builder file” error at runtime

I found some helpful information in this thread. Basically it seemed that the file was being optimized out because it was never actually being used in the code anywhere.

In order to get it working again I did a couple things, any or all of which may be necessary:

  1. Click on the TPKeyboardAvoidingScrollView classes in the project outline. Reveal the Utilities panel on the right side in Xcode if you have it hidden and confirm that the files actually have some target membership or they will not be built.
  2. Delete the app from the device or simulator you are testing on so you get a fresh load.
  3. Rebuild the project and load onto the device/simulator. The error should be gone, you should be able to hit breakpoints in the TPKeyboardAvoidingScrollView classes and it should all work now.

As an alternative you might want to look into the solution provided here by jhoule. The gist is that you add a call:
[TPKeyboardAvoidingScrollView class];
to your app delegate or elsewhere in your code to ensure that the code gets referenced and is not optimized out.

Hope that helps.

Community
  • 1
  • 1
TylerJames
  • 941
  • 8
  • 27
0

what you have to do is go to the main storyboard and add missing constraints of the scroll view or you can click on the scroll view on the storyboard and go to editor on top of the menu of xcode and go to resolve autolayout issues and click on reset to suggested constraints.run the project.Good luck.