9

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?

HajBakri
  • 91
  • 2
  • 2
  • 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 Dec 05 '13 at 12:40

3 Answers3

5

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.

Bagyr
  • 61
  • 2
  • Thx! I spent 4 hours on this bug! But I am glad i had it,learned a lot from it :D – Dobroćudni Tapir Jul 09 '14 at 07:35
  • For clarification, the crash occurs when you set the inputView to nil without first calling resignFirstResponder. – Maple Oct 07 '14 at 21:26
  • For another clarification in in my case defining my emtpyView global solved my problem. let emptyKeyboardView : UIView = UIView.init(frame: CGRectZero) – mkeremkeskin Sep 23 '16 at 06:54
  • For me this did not function. Instead I used self.textView.inputView=nil. Also compare with https://stackoverflow.com/questions/11696419/how-to-show-keyboard-after-used-inputview – EckhardN Apr 09 '18 at 10:29
1
@implementation NoKbTextField

static UIView *customInput;

- (UIView *) inputView {

    if (customInput == nil) {
        customInput = [[UIView alloc] init];
        customInput.backgroundColor = [UIColor clearColor];
    }
    return customInput;
}
Bagyr
  • 61
  • 2
  • Thank you for your input, but this doesn't solve the problem. The problem occurs when a value is assigned to inputview, and then at some point later it is assigned a nil in order to bring the system keyboard back. Your code forces the inputview property to always return a value, thus never bringing the system keyboard. That's not the desired behaviour. – HajBakri Nov 14 '13 at 19:06
0

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.

Neeku
  • 3,646
  • 8
  • 33
  • 43
kenshin
  • 36
  • 4