Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch text input without textField

Here a question for the pros... I'm developing an application on Ipad and i'm using a barcode reader with bluetooth. I have sync the barcode reader with my Ipad and I can catch the text on a textField without problems. When I read a barcode I don't want to put it on a textField, I want to catch it on a class, process it and decide what to do with it. I have searched on the internet the way to do it but I can't find it. Someone can help me? Can I do a class the delegate to receive the input strings?

I'm a little lost with it and any help will be very usefull for me

Thanks for your time!!

like image 420
Jpellat Avatar asked Jun 08 '26 19:06

Jpellat


1 Answers

I have solved the problem creating a hide textfield that become the first responder when the viewcontroller is created. After I have did the same viewController the delegate of this text field. When the BT codebar reader do a read he makes a return at the end so it calls the - (BOOL)textFieldShouldReturn: where I process the information. I hope that will be usefull for someone in the futur with the same problem. I post the code:

_textSender = [[UITextField alloc] initWithFrame:CGRectMake(150, 300, 300, 25)]; [_textSender setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:_textSender]; _textSender.hidden=YES; [_textSender becomeFirstResponder]; _textSender.delegate=self;

- (BOOL)textFieldShouldReturn:(UITextField *)textField{ [messageSenderProtocolDelegate message:textField.text]; return YES; }

It's not a beatiful way to do it and it gives me a little problem, when the BT barcode disconnects the keyboard appears and that's not good for me. I want my view clean without keyboards all the time. Now I will research if it's a function that is called when the keyboard shows to prevent him to be show

If someone have any advice it will be usefull but say thanks for your help Erik!

like image 124
Jpellat Avatar answered Jun 11 '26 11:06

Jpellat