Custom inputView breaks apart when UITextField is enabled in iOS - ios

I am working on creating a custom keypad for my iPad app. I created this keypad as a custom inputView and then assigning it to the inputView attribute for each textfield. I built this keypad in storyboard, and when I place the cursor in any textfield, the delegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(#"how about here?");
return YES;
}
gets called, but the keypad for some weird reason breaks up and is spread all over the screen. I have no idea why this is happening.
Here is what the screen looks like when the app first loads:
and here is how the app looks after I place the cursor in a textfield which calls the above method:
Here is what my screen looks like when I turn Autolayout off:
I honestly have no idea why this is happening. What am I doing wrong?
Thanks in advance to all who reply.

Related

Trying to implemen custom number pad for UITextField in iOS

I am working on an app where I have a UITableView that has a UITextField in each cell. The textfield is attached to each row via a custom cell. Because there is no number only keypad for the iPad, I have to implement my own (I don't have a choice here). I have created custom buttons for this keyboard inside MainStoryboard, attached these buttons to a view that serves as a custom inputView. These buttons all call the same method which should enter the value of the label on the button, into the textfield. Unfortunately, this is not working. I am implementing the UITextFieldDelegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(#"how about here?");
return YES;
}
which unfortunately does not get called when I place the cursor in any of the textfields, and not when I press any of the keys on the keypad, since I don't see any output on my xcode screen.
I attach the custom keypad to the inputView attribute of each textfield inside my "cellForRowAtIndexPath" method as follows:
_cell.textField.inputView = _inputView;
Can anyone see what I'm doing wrong? I figure implementing the UITextFieldDelegate would be the way to go to accomplish this (which to me appears to be very straight forward), but unfortunately I'm struggling with this. I have also included a screenshot if it helps.
Thanks in advance to all who reply.
Make
textField.delegate = self
or
_cell.textField.delegate = self;
Hope this works !!!

How to disable keyboard but enable UITextFields when using UIDatePicker?

This one is kind of hard to explain, so ask any questions you need to clarify the question. I have an iPad app (XCode 4.2, iOS 6, ARC and Storyboards).
In this app, I have a UIPopover that contains a UIView with two (2) UITextFields in it and a UIDatePicker. (see image). When I go to that scene, I have unchecked userInteractionEnabled on both textFields to prevent the keyboard from responding, which works, but doesn't allow the other UITextField to be accessed after the first one. I tried [oFinishTime setInputView:oTimePicker]; but it takes the timepicker and moves it outside of the popover, which is unacceptable.
I have touchUpInside events "wired" for each of the textFields, but neither one gets called when tapped due to UserInteractionEnabled being unchecked. I could remedy this whole thing if I could have it enabled and set a flag in the action event.
How can I enable both UITextFields yet prevent the keyboard from showing? I will be happy to post any relevant code you need to see.
May be I did not understand your problem correctly , but it seems like you all you are trying to do is Open a picker on tap and display the value set in UIPicker. You are not really using any functionality of a UItextField. A label or a button might serve the same purpose and save you from doing the extra work of disabling the keyboard.
In any case if you want to use textfield and disable keyboard picker appearing as the input view and have your own input view to it, you could do
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
You could take a look at this:
Display datepicker on tapping on textfield
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
assign delegate for each textfield and in the delegate method verify if its the one which should open picker instead of keyboard.
If it is the one then return NO
else YES
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textfield == startTimeTextField)
{
[self openPicker];
return NO;
}
return YES;
}

resignfirstresponder on a UITextView inside a UITableViewCell

I am hoping if someone can help me resolve an IOS/XCode question.
I need to have a UITextView created inside a UITableViewCell, this UITextView has responds to a user click, upon which a UIPopoverController will be displayed so that a sub-UITableView is displayed (inside the UIPopoverController) allowing a user to select from a list of choices (lines of text). After the user select the choice (one of the line of text), that line of text will then be displayed inside the said UITextView. First problem I am having is that when the user click on the UITextView the keyboard gets displayed instead of the UIPopoverController. How do I go about disabling ie. calling resignFirstResponder so that instead of the keyboard displaying, I get the UIPopoverController coming up instead. Would someone be kind enough to share similar codes? or point me to some sample of how this can be done? Thanks so much in advance.
You can use following delegate method to detect when textView is tapped and show your popOverController accordingly, return 'NO' in the delegate method so that no keyboard will appear...
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// code to show popOverController
return NO;
}

UITextField not getting keyboard input

I'm having troubles entering text into an UITextField under a SVProgressHUD (Basically an UIView with a full-screen transparent UIWindow and some UIView subviews showing text and a custom-drawn progress bar).
My problem is that the UITextField displays the blinking cursor and the keyboard shows, but when I tap a key, nothing is entered into the text field.
I only see that the cursor's blinking interrupts just like normal.
Interestingly enough, the back (delete) key works (it really deletes the last letter in the UITextView), but not any other key.
I'm using iOS 6.
Any help would be highly appreciated.
EDIT:
The same UITextField works fine when there's no SVProgressHUD displayed. This makes me think it has something to do with the first responder, but I have already tried calling resignFirstResponder on every window and subview of the SVProgressHUD and it still does not work.
I finally found the problem:
SVProgressHUD calls makeKeyAndVisible when it's initialized, because it wants to receive keyboard notifications for repositioning. I looked up what the "Key Window" actually is and found out:
...The key window responds to user input...
Now, as the UIWindow of the SVProgressHUD was the keyWindow, my other window, which contained the UITextField did not get the user input.
I finally call makeKeyWindow on the AppDelegate's window and everything is working fine.
I hope this helps anyone with similar problems.
Call resignFirstResponder() to dismiss the keyboard before showing SVProgressHUD.
Have you implemented the method....
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
...to filter out any unwanted characters? If so, perhaps it's being a little overzealous with the filtering?
For me this is worked.
I did changes in my textfield delegate method then it worked.
if ([textField isEqual:selectBankName])
{
return No;
}
else if ([textField isEqual:enterAmountTextfield])
{
return YES;
}
return NO;
}
set delegate for textfield
Make sure textfield userInteraction is Enabled.And
Finally Please check your textfield delegate method.

Programmatically show the keyboard on iPhone app

I have a view with only one UITextView that is used to enter a value. I want that when the view shows, the textview becomes the first responder (that's the easy part) and also the default keyboard shows up. I tried searching for this in speca but to no avail. There are many posts on how to dismiss the keyboard, but what I want is to show the keyboard w/o waiting for user to touch my textview.
Just setting the text field to firstResponder should do the trick.
Inside your -viewDidLoad:
[myTextField becomeFirstResponder];

Categories

Resources