简体   繁体   中英

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!!

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!

You could catch any event by using a subclassed UIApplication and overriding

- (void)sendEvent:(UIEvent *)event

The private UIEvent header declares following method

- (GSEventRef)_gsEvent;

GSEventRef is declared in a private framework called GraphicsServices . Have a look there if you can find useful info for your event.

I would try to log some flags from _GSEventGetGSEventRecord .

You can poke around, but if you need something specific make sure you file a rdar:// .

If you need to use private stuff, write your code that way it won't break when something changes (or break without crashing).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM