UITextView delegate method textViewDidChangeSelection does not receive a call when returning from the background

My ViewController implements the UITextView delegate method textViewDidChangeSelection . Everything works as expected when testing. However, if the application is placed in the background and then becomes active again, the delegate method is not called when the selection is changed in the TextView . Anyone else who has had this problem?

My subclass of UITextView does this:

 self.inputView = [[UIView alloc] initWithFrame:CGRectZero]; 

The above information is designed to prevent the keyboard from being displayed, but support for TextView is supported.

The subclass also performs the following actions:

 -(BOOL)canPerformAction:(SEL)action withSender:(id)sender{ { if ( [UIMenuController sharedMenuController] ) { [UIMenuController sharedMenuController].menuVisible = NO; } return NO; } 

This means that when you click the UITextView button, a pop-up copy does not appear. I think this method looks a little strange, but I found it on SO some time ago, and it did what it should.

+4
source share
2 answers

The problem was solved for me:

 [myTextView reloadInputViews] 

In the AppDelegate method:

 -(void)applicationWillEnterForeground: 

I don't know exactly why this works, so if anyone has a good explanation, that would be greatly appreciated.

+1
source

UITextView delegate UITextView textViewDidChangeSelection: lights up again when the application returns from the background. So there must be something else in your application.

To make sure I created a simple application with 2 UITextView , set their delegate as the view controller and add this bit of code:

 - (void) textViewDidChangeSelection:(UITextView *)textView { NSLog(@"Fire change selection."); } 

Works great both before accessing the application, and after returning from the background.

+1
source

All Articles