Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top