Catch text input without textField

主宰稳场 提交于 2019-12-21 21:34:51

问题


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


回答1:


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!




回答2:


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).



来源:https://stackoverflow.com/questions/9099866/catch-text-input-without-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!