0

I'm a newbie so hopefully this will be easy for some of you!

I have some code which works well to push the textView out of the way of the keyboard, except for one thing. I only need it to push up the text views when the bottom text view is selected, not when the top text view is selected. In fact, when the top text view is selected, the keyboard pushes it up out of view. (I hope that's clear because I don't have enough reputation to post an image).

In the notification centre, I thought I could change which object the observer is registered to receive messages from. So, as you can see in the code below, I tried using the outlet of the textView, solutionText (the bottom text view I want to trigger the method). That returned null (so all objects still call the keyboardWillShow: method). Then I added the delegate, because I'm just trying stuff, and it's still null.

Does anyone know how to register an object here so that only one of the text views will call this method?

DetailView *dv = [DetailView new];
[[NSNotificationCenter defaultCenter] 
      addObserver:self              
      selector:@selector(keyboardWillShow:)
      name:UIKeyboardWillShowNotification 
      object:dv.solutionText.delegate];

Thank you!

Paul Pan
  • 76
  • 9

1 Answers1

0

I would suggest keeping track of the active text view in the text view delegate's textViewShouldBeginEditing:. Check the active text view in the keyboard notification if(activeTextView == bottomTextView) and slide the view up only in this case.

Stonz2
  • 6,306
  • 4
  • 44
  • 64
  • This is the good way to handle this problematic. Keep the addresses of the two pointers in two attributes of class, then you can compare pointer to determine which textview is mentioned in the delegate method. – Jean Lebrument May 05 '14 at 16:40
  • This is probably a great answer, but I'm not skilled enough to implement it yet, so I'm still working on it. Essentially, I don't understand how to share a value from an instance method in one class with another class. Any tips would be appreciated but not expected – Paul Pan May 06 '14 at 17:58
  • Not quite sure what you mean. – Stonz2 May 06 '14 at 18:10
  • I'm having trouble getting the activeTextView and the bottomTextView values from Class1 in Class2, where the comparison takes place – Paul Pan May 06 '14 at 19:37