0

I want to set a custom view to the inputView property of a UITextField. (Basically because I want to add a UILabel to the selectionIndicator of a UIPickerView and I couldn't find an easier way...) If I set a UIPickerView as the inputView, everything works perfectly normal. But if I set a UIView as the inputView, it just doesn't show up when the UITextField becomes the firstResponder. Has anybody got an explanation for me here?

This works:

UITextField* field = [[UITextField alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
// configuration of field
UIPickerView* pickerView = [[UIPickerView alloc] initWithFrame:field.inputView.frame];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
field.inputView = pickerView;

This doesn't:

UITextField* field = [[UITextField alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
// configuration of field
UIView* view = [[UIView alloc] initWithFrame:field.inputView.frame];
view.backgroundColor = [UIColor redColor];
field.inputView = view;
AL3XGL355
  • 1
  • 1
  • Which UIView you set as inputView? Please post some code. – Geek Jun 17 '13 at 16:15
  • Just a normal UIView with a red background so I cannot oversee it ;-) – AL3XGL355 Jun 17 '13 at 17:18
  • I have used UIView as inputView and works for me. Can you attach an image of exactly what you want? Also if you can post the code for your UIView and when you assign it as inputView of textField. – Geek Jun 18 '13 at 04:42
  • I'm not doing anything else than in my description up there. When my textfield becomes the firstResponder and the inputView property is nil, a keyboard appears. If the inputView is an instance of UIPickerView, a pickerView appears. If the inputView is an instance of UIView, nothing happens. – AL3XGL355 Jun 18 '13 at 12:46
  • Are you sure that when you use UIView, it is not nil when textField becomes first responder? If this does not solve the problem then try cleaning the project. Also try closing Xcode and opening it again. – Geek Jun 18 '13 at 13:06

0 Answers0