I have a UIPickerView set up with an attached toolbar button that should allow the user to switch from a picker view to a keyboard view. The pickerView should slide down and a keyboard should slide up in it's place... Theoretically.
The pickerView appears when a user clicks the text field in textFieldDidBeginEditing.
elementPicker = [[UIPickerView alloc] init];
[elementPicker setDelegate:self];
elementPicker.showsSelectionIndicator = YES;
...
[_itemElementField setInputView:elementPicker];
When the user clicks the "Use Keyboard" button, I have a method to dismiss the picker and call the keyboard. I can dismiss the pickerview without a problem but CANNOT DISPLAY THE KEYBOARD!!
HELP!
Here is the method called when the user wants the keyboard:
-(void)useKeyboardClicked:(id)sender {
NSLog(#"'USE KEYBOARD' BUTTON CLICKED");
// DISMISS THE PICKER VIEW
[elementPicker removeFromSuperview];
[_itemElementField resignFirstResponder];
_itemElementField.inputAccessoryView = nil;
// SET ELEMENTPICKER TO THE DEFAULT KEYBOARD
elementPicker = UIKeyboardTypeDefault;
[_itemElementField setInputView:elementPicker];
// SHOW KEYBOARD
[_itemElementField becomeFirstResponder];
}
I'm grasping at straws now and need some help! I've even gone so far as to try to define a keyboard in the header file with
#property (strong, nonatomic) IBOutlet UIKeyboard *elementKeyboard;
but that doesn't work AT ALL.
for those that might have this issue in the future, the answer ends up being quite simple.
You need to reload the input view after resetting it to a keyboard with reloadInputViews.
Here's the code:
-(void)useKeyboardClicked:(UITextField *)sender {
NSLog(#"'USE KEYBOARD' BUTTON CLICKED");
[_itemElementField setInputView:UIKeyboardTypeDefault];
[_itemElementField becomeFirstResponder];
[_itemElementField reloadInputViews];
}
Here Is Solution Firstly you have to declare boolean variable checkFlag to keep record of useKeyboardClicked:
then
-(void)useKeyboardClick:(id)sender
{
if (checkFlag) {
checkFlag=false;
[txtField setInputView:nil];
[txtField reloadInputViews];
[txtField setKeyboardAppearance:UIKeyboardAppearanceDefault]; //you can set UIKeyboardAppearnce as Dark,light, alert instead of Default
[txtField setKeyboardType:UIKeyboardTypeDefault]; // you set decimal keyboard
} else {
checkFlag=TRUE;
[txtField setInputView:nil];
[txtField setInputAccessoryView:numberToolbar];
[txtField setInputView:pickerView];
}
}
One thing i m not total wrong but i can't set back picker view instead keyboard ..... try this i gave you hint ...
Related
In my app I have a UIWebView that shows a list of pictures. Right now, when someone taps and holds their finger on a picture, the option comes up to copy that picture.
Is there a way to make it so that, when someone taps and holds, the option to save that picture appears?
Any ideas are welcomed!
You need to detect the long tap. For that you need to add:
#property (nonatomic,strong) UILongPressGestureRecognizer *lpgr;
and in your view did load:
self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPressGestures:)];
self.lpgr.minimumPressDuration = 1.0f;
self.lpgr.allowableMovement = 100.0f;
[self.view addGestureRecognizer:self.lpgr];
and ask the user to save the picture once the app detects the long tap.
- (void)handleLongPressGestures:(UILongPressGestureRecognizer *)sender
{
if ([sender isEqual:self.lpgr]) {
if (sender.state == UIGestureRecognizerStateBegan)
{
//prompt the user to save the picture .
}
}
}
I have TableView. In each row i have textfield, three textfield have UIPickerView and two are editable, issue is when i tap on picker's textfield after tapping on editable textfield keyboard dosn't disappear here is the code
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
tf_Selected = (UITextField*)textField;
if ([textField.placeholder isEqualToString:#"Work Order "]) {
if (dicWorkOrderNoData.count > 0)
{
[ActionSheetStringPicker showPickerWithTitle:#"Select Work Order" rows:[dicWorkOrderNoData allValues] initialSelection:0 target:self successAction:#selector(selectPicker_ActionHandler:) cancelAction:#selector(cancelSheet_ActionHandler) origin:textField];
}
else if (textField.tag == DateField_UptoCurrentDate)
{
[ActionSheetDatePicker showPickerWithTitle:#"Select Date" datePickerMode:UIDatePickerModeDate selectedDate:[NSDate date] maximumDate:[NSDate date] target:self action:#selector(selectDate_ActionHandler:) cancel:#selector(cancelSheet_ActionHandler) origin:textField];
return NO;
}
else
{
return YES;
}
}
Try using [textField resignFirstResponder];.
More on that here.
It would better to assign to UITextField's inputAccessoryView Toolbar with [back, next, done] buttons, because you can't be sure that user actually selected pickerview's item or just scrolling them.
If you have few optionns, than use UIActionSheet instead.
My app is crashing in the iPad simulator when I press the action button again once it has already been pressed to open my activity view. I am concerned that this will be an issue if the user wants to press the button again to close the Popover rather than touching outside of it. Any suggestions are appreciated :)
FYI the Action button is a UIToolbar button.
In the .h
#property (strong, nonatomic) UIPopoverController *popup;
#property (strong, nonatomic) UIPopoverController *activityViewProp;
In the .m:
-(IBAction)openUIActivityView:(id)sender {
UIActivityViewController *activityView = [[UIActivityViewController alloc]initWithActivityItems:#"Hello World" applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityView animated:YES completion:^{
}];
} else {
self.popup = [[UIPopoverController alloc] initWithContentViewController:activityView];
[self.popup presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; }}
Just check if you already have a popup, and do something else
-(IBAction)openUIActivityView:(id)sender {
if (self.popup) {
[self.popup dismiss ...];
}
else {
// show popup code
}
}
The problem is, a view controller can only present one other view controller at any given time. Currently, when your tap the button a second time, you try to present a new instance of UIActivityViewController, while an other is already presented.
You can fix this, by checking the value of your main view controller's presentedViewController property. If it is not nil (and actually of type UIActivityViewController) you can return from the action without doing anything:
- (IBAction)openUIActivityView:(id)sender {
if (!self.presentedViewController) {
// We have no presented view controller yet.
// <your current code here>
} else {
// We are already presenting a view controller.
// Either dismiss it, or don't do anything.
}
I'm doing a form in an iPhone application. I'm setting the next field on the return of the keyboard. Everything works fine but if the text field is hidden under the keyboard, it's not scrolling on top of the keyboard dynamically! How can I do this?
Here is my code
It basically set to the next tag (next fileld)
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
Check out this question for sample code:
How programmatically move a UIScrollView to focus in a control above keyboard?
It sounds like what you want to use is the scrollRectToVisible:animated: method.
Here's documentation for UIScrollView to read more about the above method:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html
I have 3 uitextfield in my project
I need to when tap inside one of them (uitextfield2 ) a custom subview appear , and need the key board to appear when tap on one another (uitextfield1 )
the problem is when I tab on uitextfield1 , the keypad appear and not go even I clicked return or tap on another uitextfield2
I need the keyboard to disappear when I click out of the uitextfield1 or when click return
I use the following code
- (BOOL)textFieldShouldReturn:(UITextField *)textField { // When the return button is pressed on a textField.
[textField resignFirstResponder]; // Remove the keyboard from the view.
return YES; // Set the BOOL to YES.
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
// [textField resignFirstResponder];
[self SelectModalityClick]; // will be called If i tapped inside the uitextfield2 to display the custom view
return NO;
}
When you create your UITextField instances, you can set the inputView to whatever UIView subclass you want with something like this.
UITextField *aTextField = [[UITextField alloc] initWithFrame:aRect];
aTextField.inputView = myCustomInputView; // Set this up in your viewDidLoad method
aTextField.delegate = self;
aTextField.tag = MyCustomInputView; // #define this as some integer
[self.view addSubview];
[aTextField release];
You shouldn't need to do anything special to make the correct input view appear, if you have a UITextField instance variable for the first responder, just assign it in textFieldShouldBeginEditing: and resign its first responder status in textFieldShouldReturn:.