Objective-C: Diagnosing unrecognized selector error - ios

I am using htautomcomplete to add autocompletion to a textfield and getting the error below.
As far as I know I have made the field in question an HTautomplete field but it is saying that it is trying to send the message to an UITextField. Could this be error or what else could cause this? Thanks for any ideas.
[UITextField setAutocompleteType:]: unrecognized selector sent to instance 0x17eea9a0
(lldb)
//code creating property
#property (unsafe_unretained, nonatomic) IBOutlet HTAutocompleteTextField *titleField;

Since this is an IBOutlet, it's most likely that you didn't set the class of your UITextField in the .xib file to be an HTAutocompleteTextField.
You can do so by selecting the object in your .xib file, then going to the Identity Inspector and setting the class under Custom Class.

Related

App crashed on touch of UITextField in ios [duplicate]

This question already has answers here:
-[UIViewController _keyboard]: unrecognized selector sent to instance 0x7b731ac0
(2 answers)
Closed 6 years ago.
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:
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:
User taps your TextField.
Because of the similarly named property, UIKit Framework mistakes your custom InputViewController to be an instance of type UIInputViewController.
UIKit tries to call keyboard method of UIInputViewController on your InputViewController's instance.
keyboard method does not exist on your InputViewController because it is not an instance of UIInputViewController.
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.

Connecting next field chain for form text fields

I'm trying to connect the text fields in a sign up form so that, upon done being pressed for each, the next field in the form automatically becomes active. To achieve this, I've extended the UITextField class, as follows, in the view controller for the sign up view.
#interface UITextField (Extended)
#property (nonatomic, weak) IBOutlet UITextField* nextField;
#end
I've then set the nextField outlets via interface builder for each field in the form, and have the following code implemented in the view controller, which is also acting as the delegate for the text fields in the form.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
UITextField* field = textField.nextField;
if (field)
[field becomeFirstResponder];
return NO;
}
However when building and running the app, it immediately crashes giving the following error :
*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason:'[<UITextField 0x78729580> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key nextField.'
A bit lost as to how to address this, any help would be appreciated! Thanks in advance.
Just remove all the outlets and recreate them again. You just missed or duplicated one of them, since you have several textfields it is highly possible something has gone awry. And make sure that each nextField really points to next field :)
UPDATE: It's late night so I missed one big problem.
You can't add new properties via category to an existing class like that. The reason is category is not capable of creating a backing variable behind the scenes. (There is a way with associated objects..but it's best not to delve into that black magic.)
Instead of UItextField+extended category, subclass the UITextfield class.
#interface CustomTextField : UITextField
#property (nonatomic, strong) IBOutlet UITextField *nextField;
#end
Then in interface builder, you will have to set that CustomTextfield class in the class inspector for each text field.
The problem is that while you can declare a property in a category, the compiler will not define the property getter and setter for you. You have to define the getter and setter yourself.
You can use an “associated object” to store the property value. See this answer for example code. Since you don't want your nextField property to retain the next field, use OBJC_ASSOCIATION_ASSIGN instead of OBJC_ASSOCIATION_RETAIN_NONATOMIC when setting the associated object.

No visible interface for selector - for IBOutlet

That's a weird one:
I'm using a DMSplitView instance
Dragging it to my AppDelegate.h which creates an outlet like #property (weak) IBOutlet DMSplitView *verticalSplit;
However, whenever I'm trying to access it, in my AppDelegate.m, I'm getting an error:
No visible #interface for 'AppDelegate' declares the selector verticalSplit
How is that possible? I've done that like 10,000 times before. What sort of bug is that? Any ideas?
P.S. Just tried it as an experiment, and it's official: I cannot add any outlet whatsoever. :S
How are you defining DMSplitView? Did you use the #class directive in the header file? Did you import it in the .m file? Just wondering.

How can I connect uitextview with GCPlaceholderTextView on storyboard?

I want to use GCPlaceholderTextView
.
When I make IBOutlet UIPlaceHolderTextView model, I can't connect uitextview on storyboard. I have an error -
[UITextView setPlaceholder:]: unrecognized selector sent to instance.
How can I connect uitextview with GCPlaceholderTextView? Does anyone know?
You need to redeclare the class of your UITextView in your Storyboard and put GCPlaceholderTextView.
Otherwise the object initialized is a UITextView and not a GCPlaceholderTextView like you want. So it doesn't have the method setPlaceholder:
Like this :

UITextField possibly being released too soon and I cannot figure out where and why

Here are the areas of concern in my class:
.h
#interface TimerViewController : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *hourField,*minuteField;
}
#property (strong, nonatomic) IBOutlet UITextField *hourField,*minuteField;
#end
.m
#implementation TimerViewController
#synthesize hourField,minuteField;
#end
My issue is that I can use the text fields multiple times (retrieve and set properties) before the app crashes with this log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSCFString setText:]: unrecognized selector sent to instance 0x1e1dafa0'
This happens when the code [self.hourField setText:#"5"]; is run. It can also happen when checking if [self.hourField isFirstResponder] with the same type of log.
The console sees the text field as a __NSCFString which leads me to think it may have been released?
Runs with ARC, and I'm always using synthesised accessors. Never had this issue before and can't see where I'm going wrong.
I think the problem may be a confusion with how you declared the variables. You do not need the #synthesize statement anymore and and normally you would want to have your private iVars have a different spelling than your property declarations. To see if this is the problem remove both your #property declaration and your #synthesize and access hourField simply as [hourField setText:#"5"]; . Another way would be to remove the #synthesize and the iVar declarations altogether.
Other I would check are whether the IBOutlet is connected to the right item in your .xib or storyboard.

Resources