UITextfield and webservice - iphone

I have one query regarding the (UITextfield and Webservice) for example
When i start writing text in UITextfield. Make sure, the app does not query the server(Webservice) for each letter typed. It should wait till I make a pause and then send the request.
Is this possible to when using of UITextField?
Thanks in advance

You can do that using performSelector:withObject:afterDelay: and cancelPreviousPerformRequestsWithTarget: methods. Here's sample code - requestAction: gets called after user makes 2sec pause in editing text field.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
// Cancel previously registered perform request
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(requestAction) object:nil];
// schedule a call with 2 sec delay
[self performSelector:#selector(requestAction) withObject:nil afterDelay:2.0];
return YES;
}
- (void) requestAction{
NSLog(#"Request!");
}

Related

selectall uitextfield does not always select all

- (void)textFieldDidBeginEditing:(UITextField *)textField {
[textField selectAll:self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
In the above, the textField selects correctly but when I return from the keyboard and tap the textField for a second time consecutively, it does not select the text. If I do not pick it consecutively or if I deselect the text before returning from the keyboard, the next focus of that textField selects the text correctly.
How can I select the text in the abovementioned case?
I have found a perfect solution(invoke selectAll in next runloop):
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField performSelector:#selector(selectAll:) withObject:textField afterDelay:0.f];
}
I solved this issue using Grand Central Dispatch. You can wrap [textField selectAll:self]; with a dispatch_async call and dispatch_get_main_queue() as a first parameter.
dispatch_async(dispatch_get_main_queue()){
// ... code you want to run on the main queue goes here
}

Which TextFieldDelegate method should be called?

In my application , I want to show one popover view, whenever I am clicking in textfield.
Which text field delegate method should I call?
you have to write your functionality in
-(void)textFieldDidBeginEditing:(UITextField *)textField{
// became first responder
}
Use on the UITextFieldDelegate protocol......
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(#"Editing Should Editing"); // SAVE PROCEDURE
}

How to tell if a UITextField is firstResponder

I'm working on an app that has a signup feature. The signup process is broken up into 3 different views, each of which has 2 UITextField to take user input. I have also implemented the UITextFieldDelegate methods;
- (void)textFieldDidBeginEditing:(UITextField *)textField;
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
- (void)textFieldDidEndEditing:(UITextField *)textField;
and
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
Depending on which UITextField is in focus will determine what method is called when the user taps the return key on the keyboard. I would like to just call my resignFirstResponder method for the first 4 UITextFields but on the last textField I would like to call my join method when return is pressed.
So my question is; How can I determine which UITextField just called the textFieldShouldReturn: method?
As always, thanks in advance!
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == theLastTextField) {
//joinmethod
} else {
[textField resignFirstResponder];
}
}

how to handle key events in iphone

Hi
I am working on an iphone application and want to handle keyboard events in iphone. In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone??? Any good tutorial or sth, to get started...
You cant directly code for keyboad;s key and there is no mouse in case of device.
you can make your logics for different kind of charectersets or you can make your logics in textField delgate methods or Textview Delegates method
textView delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textField delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
You can also use Notification for textField and Textview.
For TextField use this
call this register method in viewDidLoad
-(void)registerForTextFieldNotifications {
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:#selector (handle_TextFieldTextChanged:)
name:UITextFieldTextDidChangeNotification
object:self.textField];
}
- (void) handle_TextFieldTextChanged:(id)notification {
if([iSinAppObj.passCodeString isEqualToString:lockTextField.text])
{
//code here
}
}
and for text view you need to change only event name like this
[notificationCenter addObserver:self
selector:#selector (handle_TextFieldTextChanged:)
name:UITextViewTextDidChangeNotification
object:self.textField];
You can use notifications to handle events as explained here:
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
But the functionality is very limited.

iPhone SDK: How to dismiss keyboard each time user moves to new field

We want the keyboard to be dismissed each time the user moves to a new field. What event would be appropriate to place a resignFirstResponder call?
Thanks.
Your most likely looking for the textFieldShouldReturn delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
Use the appropriate UITextFieldDelegate method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder]
return YES;
}