KahanR KahanR - 1 year ago 126
iOS Question

App crashed on touch of UITextField in ios

I added one text field in storyboard and link it with header file.

Now when I run the application I get the error like

[InputViewController _keyboard]: unrecognized selector sent to instance

I tried many things but it didn't worked.

here is interface of text field

@property (strong, nonatomic) IBOutlet UITextField *countryCode;

This is the line that uses the value of text field

NSString *body = [NSString stringWithFormat:@"country=%@", self.countryCode.text];

How can I solve this?

Connections of Textfield can be seen below:

enter image description here

Answer Source

The problem is with your name:

@property (strong, nonatomic) InputViewController *inputViewController;

Apple has added a property with similar name in UIResponder class:

@property (nonatomic, readonly, retain) UIInputViewController *inputViewController NS_AVAILABLE_IOS(8_0);

This is what happens:

  1. User taps your TextField.
  2. Because of the similarly named property, UIKit Framework mistakes your custom InputViewController to be an instance of type UIInputViewController.
  3. UIKit tries to call keyboard method of UIInputViewController on your InputViewController's instance.
  4. keyboard method does not exist on your InputViewController because it is not an instance of UIInputViewController.
  5. You get the error that an unrecognized selector is sent to your ViewController because there is no such method in your ViewController and the application correctly gets crashed.

Change the name of that property and you should be fine.

For more details, See Brian Nickel's answer here.

Also Read, Apple's documentation on UIInputViewController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download