Suraj K Thomas
Suraj K Thomas

Reputation: 5883

Hide Keypad on click of textfield IOS

I am devolepeing an app where i am entering data to a textfield from custom view(not input view).Problem is that i don't want the system keypad to popup when i touch the textfield.I have gone through Apple text programming document but was not able to find the solution.How to achieve this.

Upvotes: 1

Views: 1023

Answers (7)

Engnyl
Engnyl

Reputation: 1380

You can also use gestures,

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
    gestureRecognizer.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:gestureRecognizer];
}

- (void)hideKeyboard {
    [self.view endEditing:YES];
}

Upvotes: 4

Charan Giri
Charan Giri

Reputation: 1097

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.view endEditing:YES]; // this statement will hide keyboard. Useful when we use many textfields based on tag value. 
return YES;
}

Upvotes: 1

kamalesh kumar yadav
kamalesh kumar yadav

Reputation: 966

try this code may help you

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

if (textField==/**urs testField on which you want to remove keyboard on click*/ ) {
    [textField resignFirstResponder];
   //*its depend your requirement
    [here you can call yours custom view];
}
return YES;
}

adjust as per req..

Upvotes: 3

Ramaraj T
Ramaraj T

Reputation: 5230

Disable the editing for the particular field

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if ([textField isEqual:myTextField]) {
        return NO;
    }
    return YES;
}  

Upvotes: 1

Prabhu Natarajan
Prabhu Natarajan

Reputation: 869

Assign a IBOutlet property to that particular UITextField and then in viewDidLoad add the following code [self.YourUITextField setUserInteractionEnabled:NO];

Upvotes: 1

Kumar KL
Kumar KL

Reputation: 15335

Not sure, what exactly you are expecting. I hope that you need to handle the UITextField delegates but without UIKeyboard : If so, then implement delegate of

-(void)textFieldDidBeginEditing:(UITextField *)sender{  
// resign the textfield and do your stuff with the data 
}

Upvotes: 1

user4003752
user4003752

Reputation:

Set the userInteractionEnabled property:

//UITextField *text;
text.userInteractionEnabled = NO;

Upvotes: 2

Related Questions