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
}
Related
My view controller registers to keyboard notifications (keyboardWillShow, keyboardWillHide).
I launch my app. It is showing the viewcontroller that is registered to keyboard notifications. The keyboard is not visible.
I switch to the sms app and start writing text. While I'm writing, my app gets a notification. The notification is displayed as a banner on the top of the screen.
When I click the banner, my app is opened and immediately gets a keyboard notification.
As far as I can tell, this keyboard notification is related to the keyboard of the SMS.
How do I identify if the keyboard event came from my app or not?
you can remove listening to observers (keyboard notifications) in viewWillDisappear and can start listening to observer again in viewWillAppear, this might solve the problem
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationWillEnterBackground:)
name:UIApplicationWillResignActiveNotification
object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillDisappear:animated];
[self registerForKeyboardNotifications];
}
- (void)deregisterForKeyboardNotifications {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[center removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self deregisterForKeyboardNotifications];
}
This is HomeView
enter image description here
When Someone tapped in 'Banking' button . Action will load BaseviewController .
This is the button action.
HomeViewController.m
BaseViewController *clickbutton = [[BaseViewController alloc] initWithNibName:#"BaseViewController" bundle:nil] ;
[self presentViewController:clickbutton animated:YES completion:nil];
This is BaseView
enter image description here
There is a scrollbar which will load every view . The scrollbar
background is Green . And change the background in next here is the
problem .
BaseViewController.m
-(void)ViewDidLoad{
PriorityViewController *obj ;
UINavigationController *nav;
obj = [[ PriorityViewController alloc] initWithNibName:#"PriorityViewController" bundle:nil] ;
nav = [[UINavigationController alloc] initWithRootViewController:obj];
nav.view.frame = rect;
[self.view addSubview:self.nav.view];
}
When tapped 'Service Request' .
OtherBankTransferViewController *obj;
obj = [[OtherBankTransferViewController alloc]initWithNibName:#"OtherBankTransferViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES ];
This will load same as like second image I uploaded here .
I just want to change my background color of the scrollbar
I want to change scrollbar into black color .
I have no idea . If someone explain me !
Thanks in advance .
APPROACH 1:
Instead of initialising scrollBar in each ViewController, why not alloc init it in BaseView Controller and pass instance of it to all View Controller.
Since now all ViewControllers will have same instance it will be easy to change background of the scrollBar.
APPROACH 2:
You can post notifications whenever you want to change the scrollBar color,
add observer for the notification you are posting and with the notification you can pass the color you want to be set for all scrollBar.
Posting Notification when you want to change color
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:#"someKey"];
[[NSNotificationCenter defaultCenter] postNotificationName: #"TestNotification" object:nil userInfo:userInfo];
Adding Observer in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receiveTestNotification:)
name:#"TestNotification"
object:nil];
Method to handle received Notification
- (void) receiveTestNotification:(NSNotification *) notification{
NSDictionary *userInfo = notification.userInfo;
UIColor *backGroundColor = [userInfo objectForKey:#"someKey"];
// assign this color to your scrollBar in each ViewController
}
REMOVING OBSERVER in viewDidUnload
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"TestNotification" object:nil];
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];
}
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];
I got a UITextField, when you click on it there pops up a keyboard. I've added the UITextField using storyboard and now I want to disable a button when the keyboard pops up. How can I do this?
For disabling the button: [self.howButton setEnabled:NO];
But where do I put this?
you can add your keyboards stament to the notifacticon , when it show , then disable the button , when it hide , then enable the button
in the init to add the observer
- (void)init
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}
achieve the show and hide method
- (void)keyboardWillHide
{
[self.howButton setEnabled:YES];
}
- (void)keyboardWillShow
{
[self.howButton setEnabled:NO];
}
finally remove the observer , when the class is dealloc
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Register for UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
In the keyboardWillShow method disable your button.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
You can re-enable the button if required by registering for the above notification.