Replace textfield's keyboard on uipopover in UIwebview - objective-c

I have HTML pages with textfields and after touch on any of this textfield in UIWebView, I need to show UIPopOver with the static information and hide a keyboard.
How I can do this?

set the textfield's inputview to nil.
textField.inputView = nil;

Put this code in you viewDidLoad method, it is notification that notify you when keyboard is display
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
Add you popup view in UITextField in following method of notification
- (void)keyboardDidShow
{
if(self.myTextFieldName)
{
[myTextFieldName resignFirstResponder]; /// resignFirstResponder/hideKeyBoard when you click on UITextFiled
myTextFieldName.inputView = self.PopUpView. // and add your popup view as input view of yourTextFiled
}
}

Related

manage Tableview properties from setting view controller

I have UITabBarViewController which has 2 views.
The first view has a UITableView which has 1 section and 5 rows.
The second view has a UITableView as well which has a settings options like UISwitches.
My question is how can I show and hide or remove a cell from first view by using UISwitches on the settings view? Thanks in advance.
edit
this video explain what i am trying to do (check the app view)
Press Here
you can accomplish this by using NSNotificationCenter
in your firstView you can write a code like:
-(void)viewDidLoad{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(modifyCell:) name:#"modifyCell" object:nil];
}
//make sure this is declared in your .h
-(void)modifyCell:(NSNotification*)notif
{
if (notif) {
//cellindex to modify
NSString *cellIndex = [[notif userInfo] objectForKey:#"index"];
[yourDataSource removeObjectAtIndex:[cellIndex intValue]]
[yourTableView reloadData];
}
}
in your secondView:
-(void)switchChanged
{
NSNotificationCenter *ncSubject = [NSNotificationCenter defaultCenter];
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:#"indexNum",#"index", nil];
[ncSubject postNotificationName:#"modifyCell" object:nil userInfo:dict];
[ncSubject removeObserver:self];
}
You should reload your tableview after each UISwitch change. Such as:
- you set a delegate from your UISwitch to your UITabBarViewController (or the class which controls the events)
- you should store your tableview's cells' number in a variable
- this variable will change after each UISwitch change
- after the variable change, you should reload the tableview
In the viewWillAppear method of the table view controller I would check whether the setting has been changed or not. If it has changed then I would redraw the cell by calling its the reloadData method.
Sometimes it is recommended to call reloadData through performSelectorOnMainThread:
[ self performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO]
And your data loading methods (numberOfSectionsInTableView, numberOfRowsInSection, cellForRowAtIndexPath, etc.) will have to consider the settings value accordingly.

Calling UIKeyboard method on UITextView and not UITextFields

I have view with a UITextView for comments on the bottom. Since its on the bottom of the page, whenever someone edits it, a method is called to shift the view of the page, so that you can still see the comment box. My problem is that the same method also gets called when user are editing UITextFields.
Here's what I have. First I declare a notification:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
Then the method itself
- (void)keyboardWillShow:(NSNotification *)notif{
...
}
My first thought was to add a condition, to check and see if the object was a TextView, and only then execute the code. But since I am not passing the object to the method, is there anyway to tell the method what type of object I am dealing with
Text fields and text views also send notifications. In the textFieldShouldBeginEditing and the textViewShouldBeginEditing implementations you could set a flag that you can read in your implementation of the keyboardWillShow method -- the keyboard notification is sent after the text field or text view notifications.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
self.sender = #"text field";
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
self.sender = #"text view";
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
}
- (void)keyboardWillShow:(NSNotification *)notif{
NSLog(#"%#",self.sender);
}

How to close a modal view when the application enter in background on ios

I have a modal view created in a method (there is no reference in the mainview) and I want to do a dismissModalViewControllerAnimated automatically when my app enter in background. How can I do that ?
In the mainview's viewDidLoad, add observer to be notified when app goes to background.
- (void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(goToBackground)
name:UIApplicationWillResignActiveNotification object:nil];
}
Define the function goToBackground(). It will be called when the app goes to background
- (void) goToBackground
{
[self dismissModalViewControllerAnimated: NO]; // no need to animate
}
Don't forget to remove the observer
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
You can use a notification. Post a notification from the ApplicationDelegate's method applicationDidEnterBackground:. YOu can call the dismiss method from the modal controller, so add it as observer to the notification center.

Remove the "Dismiss keybard" key from a UITextView's keyboard on iPad

I have a modal view that with a UITextView, and the user can enter some text (or not) and close the modal view. There is no point of dismissing the keyboard as it does not dismiss the modal view (this is on purpose), and the UITextView without the keyboard just looks silly.
Is there a way to hide or remove the "Dismiss keyboard" key from the keyboard?
You can't hide or remove the key, but you can disable it using the UITextViewDelegate protocol:
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
return NO;
}
If UIKit forces the responder to resign despite the delegate (doubtful, but I haven't looked closely at the call stack), you can force the keyboard to stay up by observing the UIKeyboardDidHideNotification and setting the first responder back to the UITextView: [myUITextView becomeFirstResponder]
Protocol method doesn't help.
As Answerbot suggested one should listen to keyboard notification.
- (void)onIpadViewWillAppear
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showIpadKeyboard) name:UIKeyboardDidHideNotification object:nil];
}
- (void)onIpadViewWillDisappear
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)showIpadKeyboard
{
[myTextField becomeFirstResponder];
}
This works and looks beautifully.

IPad keyboard "Hide button"

How can I interact with the button "hide keypad"
In IPad numeric pad.
I need to add validation for this button.
Or how I can switch off this button?
This is not the delegate method for the keyboard hide button .But I think You can solve this by adding the following code to you .m file
1.Add the following code to your viewWillAppear function
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardDidHideNotification
object:nil];
2.Add the following code to viewWillDisappear function
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
3.Declare function in .h file
-(void)keyboardWillHide:(NSNotification*)notify;
4.Define function in .m file
-(void)keyboardWillHide :(NSNotification*)notif
{
//Add the code for What you wish to do after the key board hide.
}
Use this to get the moment when the user hits that button
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
//your code here
return YES;
}