9
votes

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?

3
Thanks a lot! You helped me to understand the the problem in setting inputView to nil. Luckily on our case we can not to nullify it now.yas375

3 Answers

5
votes

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.

1
votes
@implementation NoKbTextField

static UIView *customInput;

- (UIView *) inputView {

    if (customInput == nil) {
        customInput = [[UIView alloc] init];
        customInput.backgroundColor = [UIColor clearColor];
    }
    return customInput;
}
0
votes

Exactly the same problem, which eat me 4 hours.

For some reason we do not use ARC, so in the usually way, we should release the view, but the truth is if you release the view, it will crash:

[UIView _overrideInputViewNextResponderWithResponder:]: message sent to deallocated instance 0x8e88680

Only tested in iOS 5.0.1 and 7.0, 5.0.1 is just fine.