Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the inputview property of a UITextView from a custom view to nil leads to a crash

I believe I've come across a bug in iOS 7. When a UITextView is contained in a modal view, having its inputview property changed from a custom view to nil (in order to bring back the system keyboard) will cause the app to crash after the modal view is dismissed.

This crash only occurs under iOS 7. Previous versions of iOS did not exhibit this problem.

I wrote a small sample app to demonstrate the problem. Compile the launch the app and do the following:

  1. Tap the button "Show TextView". This will present a modal ViewController containing a UITextView and three buttons.
  2. Tap the button "Set inputview to emptyView". This will create an empty UIView and assign it to the inputview property of the UITextView.
  3. Tap the button "Set inputview to nil". This will assign nil to the inputview property of UITextView. This is done in order to show the system keyboard.
  4. Tap the button "Dismiss ViewController". This will dismiss the view controller to return to the original view controller.

As soon as the ViewController is dismissed, the app crashes immediately. The crash log sometimes, but not always, refers to an unrecognized selector being sent to an object. The object's type is different every time the crash is reproduced.

Has anyone else come across this sort of bug?

like image 528
HajBakri Avatar asked Nov 11 '13 18:11

HajBakri


1 Answers

I'm sorry, I'm not exactly understand you. Here is a solution that does not lead to the crash.

UIView* emptyView;

-(IBAction)setToEmpty:(id)sender {
    [self.textView resignFirstResponder];
    if (emptyView == nil)
        emptyView = [[UIView alloc] initWithFrame:CGRectZero];
    self.textView.inputView = emptyView;
    [self.textView becomeFirstResponder];
//    emptyView = nil;    // If you comment out the this line, the app will crash
}

If you enable zombie objects, you can see the following error:

CrashTest[16706:a0b] * -[UIView _overrideInputViewNextResponderWithResponder:]: message sent to deallocated instance 0x8e88680

ARC in ios7 works in a different way. Apparently you can not release the object, which was firstResponder, before closing mainView.

like image 126
Bagyr Avatar answered Oct 25 '22 06:10

Bagyr