Why is textFieldwithPlaceHolderText undefined for one view controller that conforms to UITextFieldDelegate?

StackOverflow https://stackoverflow.com/questions/18305624

Question

I have two UIViewController sublcasses, both of them conform to the UITextFieldDelegate protocol. IOW, I have these classes.

# MyVC1.h
@interface MyVC1 : UIViewController <UITextFieldDelegate>

# MyVC1.m
@interface MyVC1 () {
    // Private variable, so not a property
    UITextField *_myTextField;
}
@end

@implementation MyVC1

- (void)viewDidLoad
{
    _myTextField = [self textFieldwithPlaceHolderText:@"*Text"];
}
@end

SAME CODE for MyVC2 class, except of course the class name.

However, and this is the strange part, my code compiles for MyVC1, but NOT for MyVC2. For MyVC2, compiler says "No visible @interface for "MyVC2" declares the selector "textFieldwithPlaceHolderText". What am I missing for MyVC2? I've double- and triple-checked!

Was it helpful?

Solution 2

Ok, it's late, and I'm sleepy. MyVC1 defines the textFieldwithPlaceHolderText method, but NOT MyVC2. I cut/past the viewDidLoad section, but forgot to cut/paste the method. Sorry to waste your time.

OTHER TIPS

Like Jsdodgers said, textFieldwithPlaceHolderText is not a method of UITextFieldDelegate. Check your #imports section on both controllers - maybe VC1 imports a category for UIViewController class that adds that method to it. A category import would look like this: #import "UIViewController+_.h"

copy the method "textFieldwithPlaceHolderText" in myVc2.h in interface a and implement in myvc2.m if i post anything wrong sorry for that

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top