Keyboard Hide/Show issue in iPhone 5c - ios

From past few days I am facing a weird keyboard issue that is only happening in iPhone 5c only.
I am using objective-C for Development in Xcode-6.4
My environment target is ios7.
Here is How I am handeling keyboard Notification.
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
To Deregister Notification I am writing this piece of code.To be sure I use -resignFirstResponder for every textField.
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self hideKeyBoard];
[self.view endEditing:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)hideKeyBoard{
[kAgeTextField resignFirstResponder];
[kSchoolTextField resignFirstResponder];
}
And In submit button I have checked some condition and then I am showing an AlertView.
- (IBAction)submitClicked:(id)sender
{
if(validated)
{
[self.view endEditing:YES];
[self hideKeyBoard];
[self.view resignFirstResponder];
[self makeApiCall];
}
}
Now when I get Success/Failure Response from server I am doing this.This is the block which runs after getting response from server:
-(void)SuccessfulWithServerInfo:(id)responseInfo
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
dispatch_async(dispatch_get_main_queue(),^{
[appDelegate hideProgressViewFromView:self.view];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"" message:#"Thanks for coming" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[self.navigationController popToRootViewControllerAnimated:YES];
});
}
Problem When I get alertBox and press ok. Then keyboard opens up and closes automatically. This is happening i iPhone 5C only. I checked it in 4s,5s,6 and 6Plus. All are working fine.
If anyone knows about it please assist.

You are displaying alert at same time you are also doing popToRootViewController. May be this will cause problem.
Display alert.
Handle alert view method.
Write [self.navigationController popToRootViewControllerAnimated:YES] in alert view's method.
[UIAlertView showWithTitle:#"" message:#"Thanks for coming" cancelButtonTitle:#"OK" otherButtonTitles:nil] alertViewStyle:UIAlertViewStyleDefault tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex, NSString *text)
{
if(buttonIndex == 1)
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
Hope this will help you.

After Some Research I found this answer In stackOverflow.
Their is some change in the behaviour of AlertView in ios7 and in ios8.
I use this code to solve my issue:
[self performSelector:#selector(showAlertView) withObject:nil afterDelay:0.6];
For details answer please refer to this SO answer

Related

PopViewControllerAnimated:YES when tap on UIAlertView make Keyboard appear in parentVC

I tried to programmatically popViewcontroller
By doing this
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[[self navigationController] popViewControllerAnimated:YES];
}
The problem is I have textFields in this VC.If the textField is active and keyboard is displaying, and if I display the AlertView with use to command to resign keyboard ( [[self view] endEditing:YES] or [textField resignFirstResponder] ). And then call the command popViewControllerAnimated:YES . The current VC is dismissed but briefly after the parent VC is appear. There will be a keyboard shown for like 1 second and then disappear.
This behaviour is very annoying. Are there anyway to solve this ? I noticed that by using [[self navigationController] popViewControllerAnimated:NO] The keyboard won't appear . But I prefer to have animation in my app.
Please help.
Thanks in advance
I solved this problem my making the [[self navigationController] popViewControllerAnimated:YES]; delayed when called.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
[[self navigationController] popViewControllerAnimated:YES];
});
#KongHantrakool 's answer works but also has a shortage, you can add [[self view] endEditing:YES] or [textField resignFirstResponder] in - (void)willPresentAlertView:(UIAlertView *)alertView ,it will be better.
You can also try this code:
#pragma mark - UIAlertView Delegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self performSelector:#selector(popViewController) withObject:nil afterDelay:0.1];
}
- (void)popViewController {
[self.navigationController popViewControllerAnimated:YES];
}
Try this i think its may help you
- (void)viewWillAppear:(BOOL)animated
{
[textField resignFirstResponder];
}
I encountered this problem too, and I found out that the delay solution does not work at all. alertView will remember the status of the keyboard, so when the alertView is dismissed, it will restore the keyboard. So the issue comes out: the keyboard appears about 1 second after we pop the viewController.
Here is my solution:
We just need to ensure the keyboard's status is hidden, before we pop the viewcontroller.
First we add a property and register the keyboard notifications to monitor the keyboard's status:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
#property (nonatomic) BOOL keyboardDidShow;
Implement the funs:keyboardDidHide: and keyboardDidShow:
- (void)keyboardDidHide:(NSNotification *)notification {
self.keyboardDidShow = NO;
if (self.needDoBack) {
self.needDoBack = NO;
[self showBackAlertView];
}
}
- (void)keyboardDidShow:(NSNotification *)notification {
self.keyboardDidShow = YES;
}
Do your pop:
- (void)back {
if (self.keyboardDidShow) {
self.needDoBack = YES;
[self.view endEditing:YES];
} else {
[self showBackAlertView];
}
}

Start function from popover view controller

I have main viewcontroller that opens via popover segue other view controller with buttons.
On button click what I wish to happen is function from first viewcontroller fire and the popover will close. How do I do so properly?
On settings button click the popover open. Then when user click Manual Content Update the the view will close and start function on Projects Main viewController.
You can use NSNotificationCenter.
In your main UIViewController add:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receivePopoverNotification:)
name:#"PopoverNotification"
object:nil];
}
-(void) dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void) receivePopoverNotification:(NSNotification *) notification
{
[self.popover dismissPopoverAnimated: YES];
self.popover = nil;
}
In your UIPopoverController add:
-(IBAction) pressButton: (id) sender {
[[NSNotificationCenter defaultCenter]
postNotificationName:#"PopoverNotification"
object:nil];
}

Is it possible to make a background ViewController unclickable?

So I've got a UIActivityViewController that takes up half the screen when my app runs, what happens is when I click the half it doesn't take up then it'll disappear and my original blank ViewController appears.
Is it possible to permanently keep the UIActivityView up until the user clicks on one of the sharing options (such as Facebook, or Mail)? Otherwise I'll just work around it.
I load the ActivityView with:
-(void)viewDidAppear:(BOOL)animated{
UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:#[#""] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}
Yes, it is possible, you can try something like
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showAViewController) name:#"showAViewController" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dissmissAViewController) name:#"dissmissAViewController" object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter]removeObserver:self name:#"showAViewController" object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:#"dissmissAViewController" object:nil];
}
-(void)showAViewController{
self.view.userInteractionEnabled=NO;
}
-(void)dissmissAViewController{
self.view.userInteractionEnabled=YES;
}
When you are showing a view controller on top of another view controller just call
[[NSNotificationCenter defaultCenter] postNotificationName:#"showAViewController" object:nil];
After you dismiss it or remove it, just call:-
[[NSNotificationCenter defaultCenter] postNotificationName:#"dissmissAViewController" object:nil];

Modal popup behind keyboard

I have a modal popup which is placed behind the keyboard.
How can I move the modal popup to a higher position?
This is work around to get rid of mentioned situation.
I assume you are using becomeFirstResponder for textField. Write below code in class which is presented modally.
-(void)viewDidAppear:(BOOL)animated{
[self performSelector:#selector(txtFieldResponder) withObject:nil afterDelay:0.1];
}
-(void)txtFieldResponder{
[self.txt becomeFirstResponder];
}
Hope this helps.
Use this:
Register class for keyboard show and hide notification
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:#selector(showKeyboard:) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:#selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
Then implement
- (void)showKeyboard:(NSNotification *)notification {
//Change popup frame here
}
- (void)hideKeyboard:(NSNotification *)notification {
//Change popup frame to previous state
}

"UIKeyboardWillShowNotification" cannot be received on iPad mini

I added following code to viewWillAppear:animated in main view controller.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
And, I implemented this method in same class,
- (void)showKeyboard:(NSNotification *)notification
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Keyboard will appear." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Main view controller has a UITextField object.
In iPad2 (iOS 5.0), an alert view appears when it was focused.
However, in iPad mini (iOS 6.0), nothing appears except a software keyboard.
I want to make iPad mini be same behavior as iPad2.
Thanks,
As of iOS 3.2, UIKeyboardWillHideNotification and UIKeyboardWillShowNotification are no longer fired when switching between two text fields. Basically, the notifications only fire if the keyboard is actually shown or hidden. Use UIKeyboardDidShowNotification instead.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];

Resources