xcode 4.3 - UITextField - Custom Keyboard - objective-c

I have two TextFields and I am designing a custom keyboard for ipad.
How can I dissmis system keyboard and let mine apear.
how can I know that the user is activating which TextField?

Setting the delegate to textfields to your view controller instance you have to implement this method:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
and if you return YES it will open the system keyboard, if you return NO it won't.
Before returning NO, of course, you can show your view.
You will know which textField is "pressed" using tag property.

Related

iOS7 Keyboard Behavior with SearchBar/UITableView: Offset on secondary view appearances

Problem
I am having a rather big issue with the iOS7 keyboard appearance. I have a Searchbar on a UIViewController with TableView Delegation/Data Source setup (I am using the self.searchDisplayController delegates as well). I segue from this scene to a prototype tableview to show the results.
Here is the issue:
On first load I can see the keyboard being displayed when I tap into the text field of the UISearchBar. I can type and perform a search with the results being shown in the next scene.
I've added NSNotifications to view the keyboard properties in local methods keyboardWillShow and keyboardWasShown. I can see on the first scene appearance (after the view is completely loaded):
I segue to the result tableview at this point and when I navigate back and touch the text field, my keyboard shows up either fully or partially off-screen:
When I look at the keyboardWillShow notification at this point I can see that my keyboard values are incorrect:
I've researched and tried many possibilities including:
Added the following to my main view controller:
-(BOOL)canResignFirstResponder
{
return YES;
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
Configured the following in my view did load
self.searchDisplayController.searchBar.spellCheckingType = UITextSpellCheckingTypeNo;
self.searchDisplayController.searchBar.autocapitalizationType= UITextAutocapitalizationTypeNone;
self.searchDisplayController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchDisplayController.searchBar.keyboardType = UIKeyboardTypeDefault;
Put in standard stubs for:
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
I've noticed that if I choose a Partial Curl as my segue mode, the keyboard remains accessible when I roll back to the main view controller (but then it was never fully off screen in that case). However if I move from the results tableview to a detail scene and then navigate back to the main view controller, the keyboard appears off-screen again.
Question
Is there a method I can use to intercept the misplaced keyboard so that it displays in the default location?
NB: Along these lines, I have created a NSDictionary property to hold the initial userInfo values with the correct keyboard placement. I am not sure how to reassign these values to get the keyboard to return to it's original placement.
BTW - This seems a bit of a hack to get the keyboard fixed due to a bug in IB, is there some other way that I can try to remedy the situation?
Thanks in advance for any feedback!
Solution
This was such an obscure issue that I'm sharing the solution to save the next person some effort. Like most programming issues, it turns out this one was self-inflicted. In my original iteration of this project I had turned off rotational support as I am learning auto-layout and I wanted to ease into the transition from Springs and Struts. Somehow between the start of the project and the code release I ended up with this bit of code in the Main Scenes' View Controller.
//BAD
- (NSUInteger) supportedInterfaceOrientations
{
return !UIInterfaceOrientationPortraitUpsideDown;
}
instead of returning a valid enumeration like...
//OK
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}

Hide the keyboard for UITextField in the same UIViewController with UISearchbarDisplayController

How can I hide the keyboard only for specific UITextFields?
I have a lot of UITextField in a View Controller, which has also a SearchbarDisplayController.
I tried to use this but it blocks the UISearchbarDisplayController's job.
Thank you.
For more detail:
For example I have 3 UITextFields and a searchbar display controller. If there is only UITextFields , while tapping out ofthe keyboard, the keyboard successfully disappear. But when I touch the searchbar, you know the keyboard is open and I enter some text to searchbar. So it gives me some results in searchresultstable of the searchbar. But I can't select any row from searchresultstable. Because the disapper keyboard blocks it.
it seems to me that in this tutorial this method has not been implemented, try to add it
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}

Xcode - setFocus on a text field, becomeFirstResponder isn't enough

At the moment, I trigger a method on 'Did End On Exit' in my app (I'm aware that this may not be the greatest way of doing it but I'm very new to Objective C and Xcode for that matter and I'm simply doing what feels comfortable to me).
This method resigns the firstResponder from the current text field and applies it to a later text field.
The problem I'm facing is that the keyboard covers the next text field so that the use has no idea where the focus is and therefore what they are required to type.
How do I get it so that my keyboard shifts down and actually shows the text box that is currently active? Making something the firstResponder simply doesn't do what I want it to, unless there's part of the implementation I'm missing.
Here's my simple method:
- (IBAction)firstNameNext:(id)sender {
[firstNameTextField resignFirstResponder];
[surnameTextField becomeFirstResponder];
}
Any advice would be super.
Add UIScrollView in your main view then all contents as subview to UIScrollView
Now when specific UITextField needs to be able to visible in view use its delegate like this:
Note: add UITextFieldDelegate in .h file like this
#interface yourViewController : UIViewController<UITextFieldDelegate>
Also bind with File's Owner
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
{
if(textField == yourSpecficTextField) //one u want move upwards
{
yourScrollView.contentOffset = CGPointMake(0,200); //required offset
}
... //provide contentOffSet those who needed
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
yourScrollView.contentOffset = CGPointMake(0,0); //make UIScrollView as it was before
}
If you have keyboard input fields that will be covered by the virtual keyboard, then you need to move those fields out from under the virtual keyboard.
The normal way to do this is to have the controller's view be a scrollable view like UIScrollView. Moving Content That Is Located Under the Keyboard gives a very robust way of adjusting your scroll view and ensuring the required field shows.

Hide keyboard when hitting return key in IOS5

I have tried this solution to hide keyboard but it doesn't work...
How to hide the keyboard when i press return key in a UITextField?
Many thanks
assuming you are using UITextField, how do you create the textfield? is it by xib? or by code? make sure you implement UITextFieldDelegate in your class
#interface YouClass : UIViewController <UITextFieldDelegate>
if its xib, connect your textField to the file owner's delegate. and also connect your File owner to your IBOutlet UITextField
if its by code. just do
yourTextField.delegate = self;
now implement
-(BOOL)textFieldShouldReturn:(UITextField *)textField
Just resign as first responder in your input text field, when the return key pressed. The keyboard will dismissed automatically.
You need to set the Return button to actual built in function type. In one of my apps I have set it as a "Done" button because when the user has finished they can press this and it will drop the keyboard away. To set this add this to your code in somewhere like the -(void)viewDidLoad; method.
textFieldName.returnKeyType = UIReturnKeyDone;
That should then give you a blue done button on the keyboard that hides it.

Objective C , Keyboard issue

I am using XCode 4.2 .
is there a way to push the UITextField up when the user is entring text ?
the problem is that the UITextField is located behind the keyboard when it appears ...
Thanks
The one way is to simply manually shift the uitextfield up. You can simply use the delegate methods for uitextfielddelegate on begin editing and end editing to do your transformation.
Follow this.
Here is a simple tutorial on how to animate the textfield up when the keyboard comes up. The idea is to implement the UITextFieldDelegate methods like this
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD UP
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD DOWN
}
The tutorial has all the details along with working code.