Uitextfield -Webview No Longer Supported

UIKeyboard not appearing when tapping on UITextField

Following will fix the keyboard issue

Simulator -> Hardware -> Keyboard -> Toggle Software Keyboard should solve this problem.

![Simulator->Hardware->Keyboard->Toggle Software Keyboard]

UITextField in UITableView post 3.0 should automatically support scrolling above the keyboard?

My problem was that my class was a subclass of UIViewController when it needed to be UITableViewController.

UITextField replace text with NSUndoManager Support

Shake-to-undo
Put this line in your appDelegate's application:didFinishLaunchingWithOptions: method:

    application.applicationSupportsShakeToEdit = YES;

and in the relevant viewController.m

    -(BOOL)canBecomeFirstResponder {
return YES;
}

the rest of this code goes in viewController.m

Property
Put this in the class extension...

    @interface myViewController()
@property (weak, nonatomic) IBOutlet UITextField *inputTextField;
@end

link it up to your text field in Interface Builder.

Undo method
Adds an invocation of itself to the redo stack

    - (void)undoTextFieldEdit: (NSString*)string
{
[self.undoManager registerUndoWithTarget:self
selector:@selector(undoTextFieldEdit:)
object:self.inputTextField.text];
self.inputTextField.text = string;
}

(we do not need to create an NSUndoManager instance, we inherit one from the UIResponder superclass)

Undo actions
Not required for shake-to-undo, but could be useful...

    - (IBAction)undo:(id)sender {
[self.undoManager undo];
}
- (IBAction)redo:(id)sender {
[self.undoManager redo];
}

Invocations of the undo method
Here are two different examples of changing the textField's contents…

Example 1
Set the textField's contents from a button action

    - (IBAction)addLabelText:(UIButton*)sender {
[self.undoManager registerUndoWithTarget:self
selector:@selector(undoTextFieldEdit:)
object:self.inputTextField.text];
self.inputTextField.text = @"text";
}

Risking loss of clarity, we can shorten this to:

    - (IBAction)addLabelText:(UIButton*)sender {
[self undoTextFieldEdit: @"text"];
}

as the undoManager invocation is the same in both methods

Example 2
Direct keyboard input editing

    #pragma mark - textField delegate methods

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.undoManager registerUndoWithTarget:self
selector:@selector(undoTextFieldEdit:)
object:textField.text];
return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//to dismiss the keyboard
[textField resignFirstResponder];
return YES;
}

in iOS 8 when clicking on uitextfield keyboard is not open

In your iOS simulator, make sure that you've unchecked Hardware > Keyboard > Connect Hardware Keyboard.

No consecutive spaces Swift UITextField

Just check the previous and the current character entered by the user.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

if textField.text?.characters.last == " " && string == " "{

// If consecutive spaces entered by user
return false
}

// If no consecutive space entered by user

return true

}


Related Topics



Leave a reply



Submit