Keep a hardware (bluetooth) keyboard from overriding an inputView in iOS 8 - ios

I have a UITextField that uses a custom UIPickerView in its inputView to restrict the user to a few options, functioning analogous to a dropdown list. When used with a hardware keyboard connected via bluetooth, the hardware keyboard overrides (and hides) my inputView. The associated inputAccessoryView remains, however. When press the "keyboard" button on my hardware keyboard (which would normally display the default on-screen keyboard for a vanilla UITextField), everything works as expected. (By which I mean my inputView is visible again.) In prior version of iOS (i.e. 7 and below), the inputView was always visible when called.
I have temporarily solved the problem by setting the UITextField's UIKeyboardType from UIKeyboardTypeDefault to UIKeyboardTypeTwitter, but this will only work while the hardware keyboard is not recognized as the default for that particular UIKeyboardType. Code is pickerTextField.keyboardType = UIKeyboardTypeTwitter; (See about 2/3 of the way into the code below.) Upon further testing, this partial solution isn't nearly as useful as it seems.
How can I correctly display my inputView in all situations while using a hardware keyboard?
Relevant code snippet:
-(int)setUpPickerWheelAtXLoc:(int)xLoc andYLoc:(int)yLoc {
int qwidth = width - (xLoc - FORMBORDERLEFT);
// Set up inputView (pickerView) to replace the keyboard
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, height)];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerTextField = [[UITextField alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, 32)];
self.pickerTextField.delegate = self;
pickerTextField.borderStyle = UITextBorderStyleRoundedRect;
pickerTextField.layer.borderWidth = 0.3f;
pickerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
pickerTextField.textColor = [UIColor blackColor];
pickerTextField.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
pickerTextField.placeholder = #"Tap to choose from list...";
// Add pickerView as inputView
pickerTextField.inputView = self.pickerView;
pickerTextField.keyboardType = UIKeyboardTypeTwitter; // Suggested temporary solution
// Setup inputAccessoryView (Done button)
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton addTarget:self action:#selector(pickerDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:#"Done" forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
doneButton.frame = CGRectMake(0,0,100,44);
[doneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
doneButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
doneButton.backgroundColor = [UIColor lightGrayColor];
pickerTextField.inputAccessoryView = doneButton;
return xLoc + qwidth;
}
Additional Info: After checking a few other places, I have confirmed that this is happening in at least one Apple product as well. (In the "Create New Apple ID" app/page on an iPhone 6 in 8.0.2. See the Date of Birth pickerviews for Month and Day.)

The issue was fixed by Apple in the iOS 8.1 update.

Related

UIButton not work in Landscape mode

After rotation of iPad in my simulator i found a strange bug - my UIButton have visible title, it property enables is YES, but, its not work. I tried to set background colour of button to black, and found that after rotation it vanish. Please take a look at portrait mode (all work):
And landscape mode (not work):
This is how i create button (i doubt that it help though, because its pretty mundane):
self.readNextButton = [UIButton new];
self.readNextButton.backgroundColor = [UIColor blackColor];
// self.readNextButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[self.readNextButton setTitleColor:[UIColor colorWithHexString:#"#60aabf"] forState:UIControlStateNormal];
self.readNextButton.titleLabel.lineBreakMode = NSLineBreakByClipping;
self.readNextButton.titleLabel.font = [UIFont fontWithName:#"Times New Roman" size:14];
[self.readNextButton setTitle:#"Читать дальше" forState:UIControlStateNormal];
[self.view addSubview:self.readNextButton];
Also, i want to notice that this bug appears even when i'm not rotating anything, but simply load app in landscape mode. And also, ENABLED property of button is 1 (mean YES), when i log it..
Button frame:
[self.readNextButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.containerForNewsText.mas_right).with.offset(-10.834);
make.bottom.equalTo(self.containerForNewsText.mas_bottom).with.offset(-10.834);
make.top.equalTo(self.truncatedNewsText.mas_bottom).with.offset(20);
}];
It is in a method 'createLandscapeConstraints', that called in end of viewDidLoad.

ios 8 : When clicked inside UITextview, keyboard not popping but works well in ios 7

It is still working well in ios 7, UITextView is added to popover and displayed.
UITextView *textViewComment =[[UITextView alloc]init];
textViewComment.tag = 2001;
textViewComment.delegate = self;
textViewComment.frame=CGRectMake(15,60, 370,120);
textViewComment.contentInset = UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 0.0f);
[textViewComment setReturnKeyType:UIReturnKeyDone];
textViewComment.textAlignment = NSTextAlignmentLeft;
textViewComment.showsHorizontalScrollIndicator = NO;
textViewComment.bounces = NO;
textViewComment.layer.borderColor = [[UIColor lightGrayColor]CGColor];
textViewComment.layer.borderWidth =1.0f;
[textViewComment addSubview:commentPlaceHolderLabel];
[popupViewController.view addSubview:textViewComment];
On ios8 adding textViewComment.keyBoardType = UIKeyboardAlphabet, textViewComment.enable = YES; didnt help. I dont know what mistake I am making. Is this new sdk bug? or my bug?
Thanks in Advance
Are you working in the simulator ?
Because by default the hardware keyboard is selected and the simulator's won't show up.
You can change that by going into menu "Hardware" -> "Keyboard" and deselect "Connect Hardware Keyboard"

Cannot make programmatically created UITextField editable (iOS)

I created a UITextField programatically, (I do not use storyboard) and added it as a subview to ViewController with this code:
#interface ViewController ()
#property (nonatomic, strong) UITextField *searchLocationBar;
#end
...
#synthesize searchLocationBar;
...
self.searchLocationBar = [[UITextField alloc] init];
self.searchLocationBar.frame = CGRectMake(0.0f, 0.0f, 320.0f, 40.0f);
self.searchLocationBar.delegate = self;
self.searchLocationBar.borderStyle = UITextBorderStyleRoundedRect;
self.searchLocationBar.placeholder = #"a temporary placeholder";
self.searchLocationBar.userInteractionEnabled = YES;
self.searchLocationBar.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.searchLocationBar];
However, I cannot enter any text - nothing happens, when I tap on a textfield. It's not overlapped by any other view.
I've checked UITextfield not editable-iphone but no effect
I'm newbie and totally sure I simply miss something - please advice.
Thanks!
EDIT:
One more thing: I have a Google Maps GMSMapView assigned to self.view as
self.view = mapView_; as written in Google API documentation.
After some tests I found that with this declaration all controls work perfectly, but not textfields. I would prefer not to move a map view to any subview as I will need to rewrite lots of things.
Can someone please add any suggestions?
you forget add:
[self.view bringSubviewToFront:self.searchLocationBar];
In Xcode 5 your code should work.Better you check your Xcode version.May be the problem with your code with Xcode versions.You can try by following way.
UITextField *lastName = [[[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
[self.view addSubview:lastName];
lastName.placeholder = #"Enter your last name here"; //for place holder
lastName.textAlignment = UITextAlignmentLeft; //for text Alignment
lastName.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0]; // text font
lastName.adjustsFontSizeToFitWidth = YES; //adjust the font size to fit width.
lastName.textColor = [UIColor greenColor]; //text color
lastName.keyboardType = UIKeyboardTypeAlphabet; //keyboard type of ur choice
lastName.returnKeyType = UIReturnKeyDone; //returnKey type for keyboard
lastName.clearButtonMode = UITextFieldViewModeWhileEditing;//for clear button on right side
lastName.delegate = self; //use this when ur using Delegate methods of UITextField
There are lot other attributes available but these are few which we use it frequently.if u wanna know about more attributes and how to use them refer to the following link.
You can also make property for UITextField.Either way should work fine in Xcode.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html

UITextField Number Pad not working

_text = [[UITextField alloc] initWithFrame:CGRectZero];
_text.font = [Styles bodyFont];
_text.text = ((EditTextBubble *)(toEdit.bubble)).textLabel.text;
if ([_text.text isEqualToString:[#"E.g. " stringByAppendingString:((EditTextBubble *)toEdit.bubble).placeholder]]) _text.text = #"";
_text.textAlignment = NSTextAlignmentLeft;
_text.delegate = self;
_text.userInteractionEnabled = NO;
[self addSubview:_text];
_text.keyboardType = UIKeyboardTypeNumberPad;
I'm trying to get the number pad (http://cdn.arstechnica.net/wp-content/uploads/2013/09/keypad.png) to work for UITextField but all I get is the normal keyboard on the numbers page, not that google image above. How do you get it to work? This is on iOS 7 and on ipod/ipad, and without the nib file.
If you need to display a numpad keyboard on iPad, you will need to build your own (or use an open source), and set the text view's inputView to the view you created. But don't be alarmed, this is quite easy to do.
On iOS7, use UIInputView to get a similar look and background to the native keyboard.
An example of Apple's custom numeric keyboard on iPad in their Numbers app:

A UIButton above a UIPickerView

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.
and here is my code where I initiate a UIPickerView as well as its dismiss button:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:#"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:#selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this:
apparently there is a button on the upper right of the pickerView,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.
Can anyone help me with this?
Thanks a lot and a lot!
I found the reason, it seems the png has some problem,
after I change another png, it comes up in the screen!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.
But anyway the pickure is only a small problem.

Resources