vlad.grb
vlad.grb

Reputation: 339

UITextField in NavigationBar

I just put UITextField in NavigationBar using xCode. But when I try to create IBOutlet binding my programm receive -[UITextField isEqualToString:]: unrecognized selector sent to instance. Any suggestions? Thnx.

Upvotes: 2

Views: 5358

Answers (5)

Raphael Oliveira
Raphael Oliveira

Reputation: 7841

UITextField *textField = [[UITextField alloc] init];
// configure text field
self.navigationItem.titleView = textField

Of course you could also use a property in your view controller instead of a local variable.

Upvotes: 0

Mike A
Mike A

Reputation: 2529

Please provide some sample code or a screenshot if you want a good answer. May I suggest you read this document for future questions.

This is clearly a case of you calling isEqualToString on a UITextField when this is a method that must be called on a NSString.

Upvotes: 0

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

Try this

-(void)viewDidAppear:(BOOL)animated{
    UITextField *txtField=[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
    [txtField setBorderStyle:UITextBorderStyleRoundedRect];
    txtField.text=@"Hello";
    [self.navigationController.navigationBar addSubview:txtField];
}

Will look like..

enter image description here

Upvotes: 3

Sahil Mahajan
Sahil Mahajan

Reputation: 3990

isEqualToString is method of string class not UITextField. Thatswhy you get this error. You are passing method to wrong object. Use textField.text instead of textField alone

Upvotes: 0

runmad
runmad

Reputation: 14886

You have to call it on the UITextField's text property:

UITextField *myTextField = [[UITextField alloc] initWithFrame:...];
myTextField.text = @"someString";
...
[myTextField.text isEqualToString:@"someString"]

Upvotes: 3

Related Questions