0

I need guidance because it seems like I've misunderstood some concepts. All I'd like to achieve is to have a UIPickerView as the inputView of a UITextField. It's easily done by self.textField.inputView = self.pickerView. The problem with this is that you still have a blinking cursor and that a device with a BT keyboard can still type text in the textfield. So I've read about custom UIViews that can act as First Responders. I've subclassed UIView and added canBecomeFirstResponder, canResignFirstResponder, becomeFirstResponder and resignFirstResponder, all of them returning yes. Problem is, when I tap the view, nothing happens. Defining a custom inputView didn't help, it just acts as if nothing happened.

Any guidance is appreciated. Thanks, Z.

Zoltán
  • 1,422
  • 17
  • 22

2 Answers2

1

You need to create Custom TextField and override the following method.

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return CGRectZero;
}

Now use this custom textfield to create your required Textfield and set its input view as pickerview. The above method will remove the blinking cursor.And for text to be not entered from any BT Keyboard, you should do this in delegate method of textfield

//Prevent text from being copied and pasted or edited with bluetooth keyboard.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        return NO;
}
0

1.create a subclass of the (UIview)UIResponder class

2.redeclare inputview as read-write

@property (nonatomic, strong, readwrite) UIView *inputView;

3.set canBecomeFirstResponder to YES

- (BOOL)canBecomeFirstResponder {
return YES;
}

4.set inputview such as datepicker

self.inputView = self.datePicker;

5.set UIResponder to firstResponder when you want

[self becomeFirstResponder];

5.you can see datepicker show like keyboard

wlixcc
  • 1,132
  • 10
  • 14