Search code examples
iosuitextfielduitextfielddelegate

UITextfield not displaying text on it ,if text is typed


I have created a uitextfield programatically,also added uitextfield delegate protocol. But the problem is that, even though it is displaying the text field, it is not displaying any text if typed (or I am not able to enter anything to text field. it remains blank). Code is given below. Actually I used same code in another class and was working properly there, not understanding what is the problem. Please help.

txtSIBBBbidSearch=[[UITextField alloc]initWithFrame:CGRectMake(50, 335, 150, 25)];
txtSIBBBbidSearch.clearsOnBeginEditing=YES;
txtSIBBBbidSearch.clearButtonMode=YES;
txtSIBBBbidSearch.delegate=self;
[txtSIBBBbidSearch setPlaceholder:@"Your Name"];

In another class

[self.view addSubview:viewcontroller.txtSIBBBbidSearch];

In the .h of above class where addsubview is given, I have also added UITextfielddelegate


Solution

  • I guess you are returning NO to your textFieldShouldReturn delegate method. you should return YES.

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        return YES;
    }