IPHONE: ABPeoplePickerNavigationController hidden navigation bar - iphone

Hello I have a ABPeoplePickerNavigationController, on creation is set its
navigationBar hidden.
peoplePickerController.navigationBar.hidden = YES;
This works perfectly, the only problem is that when the user taps the search box
to search for a person, as he return's from the search, the navigationBar is re-displayed,.
How can I get notified of this and make the navigationBar hidden again ?
I also think this is an apple bug, since on regular cases when search is tapped,
the navigation bar is hidden to make for more room, and later displayed, but
it does not take into account the fact that the bar could have been hidden in
the first place.
Any trick's welcomed.

The safest and simplest method is to track when the keyboard hides/shows.
- (void)keyboardWillHide:(NSNotification *)notification
{
peoplePickerController.navigationBar.hidden = YES;
}
- (void)hideNavbarAndKeepHidden
{
peoplePickerController.navigationBar.hidden = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

If you believe this is a bug you should submit it to http://bugreporter.apple.com.
To me it also sounds like a bug, but I'd double-check with the documentation to make sure. If it doesn't mention anything, then I suggest reporting the bug.
Edit: On the other hand, I would think setting the navigation bar here to be hidden is a bad idea. Is there a particular reason for wanting to hide it?

Related

In terms of iphone application, the way to reload displayed page automatically when a background app comes back to be active

I have developed an iphone application with Phonegap/Cordova v1.9.0.
I want to realize the following matter.
-When a background app comes back to be active(When the app icon is tapped), a displayed page is reloaded automatically-
Probably I should make some programs in a function, (void)applicationDidBecomeActive, in Appdelegate.m or MainViewController.m, but I have no idea what to do.
Please tell me how to solve this case.
You can use the NSNotification observer pattern. In your MainViewController.m file, and viewDidLoad, you can add an observer (registering for notifications):
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(appDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
Then you must implement appDidBecomeActive: (you can give the selector any name, but you must implement a method of that name). In this example:
- (void)appDidBecomeActive:(NSNotification *)notification {
NSLog(#"App became active");
}
When the app is resumed, and should this view controller be active, it will simply log that to the console. You can put any code you wish inside that method (in your case, refreshing a page).
Don't forget to remove the observer when the view controller is deallocated in the dealloc method. This will remove all observers for you.
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(#"Removed all notification observers");
}
Are you really using version 1.9?
Try this:
document.addEventListener("resume", onResume, false);
function onResume() {
// Handle the resume event, reload the page or content
}

keyboard dismiss without animation when used in UIWindow with windowLevel greater than UIWindowLevelAlert

I am currently presenting a security code view controller that contains a UITextField in which the user is supposed to enter a passcode. This security code view controller is presented in its own window which has a "windowLevel = UIWindowLevelAlert + 1;" because i want to hide potential UIAlertView or other windows that could be present already displayed.
The problem comes when i call the resignFirstResponder method on the textfield, it seems that the keyboard is dismissed without the usual animation.
I tried to register to the various keyboard notification, and checked the UIView areAnimationsEnabled property and it returns YES.
So if anybody already had this issue, you're welcome :)
UIKeyboardAnimationDurationUserInfoKey is a constant string identifier the animation duration, so there is where of enabling and disabling the animation.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(willHideKeyboard:)
name:UIKeyboardWillHideNotification
object:nil];
- (void)willHideKeyboard:(NSNotification *)notification {
[UIView setAnimationsEnabled:NO];
}

Can I disable the keyboard from showing in a UIWebView?

Is it possible to disable the keyboard from showing when a webpage element is selected inside a UIWebView?
Register for a keyboard notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
And then you can stop it from showing by placing the following code in keyboardWillShow :
UITextField *dummyTextField = etc.
//Basically, create a dummy uitextfield that you never show.
//I can't remember all the syntax :)
[dummyTextField becomeFirstResponder];
[dummyTextField resignFirstResponder];
//Keyboard should be gone. Hoorah!
Not sure 100% if this will work without flaws. If the keyboard starts to animate then hides itself again, you could use
[UIView enableAnimations:NO];
If the keyboard doesn't like being resigned while it's showing then you could try changing the inputView property of the dummy textField to some dummy UIView instead.
Hopefully this should get you somewhere!

UIKeyboardWillShowNotification, UIKeyboardWillHideNotification and NSNotificationCenter problem between iOS versions

I have several UITextFields on my view (each inside a UITableViewCell). When the keyboard is fired from any of the textfields, I need to make some animations, mainly to change the frame of the UITableView. The same must happen when the keyboard will hide.
I have done the animation, so this is not the issue here.
Now, I use NSNotificationCenter to catch displaying/hiding of the keyboard:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
The problem is when the keyboard is visible (a textfield is used) and I press inside another textfield. Usually for this thing keyboard will not hide, but will stay visible.
It works fine in iOS 4, but the problem comes in 3.1.3 (this is the version that I can test - possibly any version below 3.2). In versions older than 3.2 changing focus from a textfield directly to another textfield will fire the UIKeyboardWillHideNotification and UIKeyboardWillShowNotification.
Anyone knows a way to perform some animation when the keyboard will really show/hide, without the NSNotificationCenter?
Or how can I overcome this issue with versions lower than 3.2?
Thanks.
What you can do is set the textfield's/textview's delegate to the current view controller and implement these 2 methods
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
_keyboardWillHide = NO;
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
_keyboardWillHide = NO;
return YES;
}
After that in your method that get's triggered by the UIKeyboardWillHideNotification notification you can do something like
if (_keyboardWillHide) {
// No other textfield/textview was selected so you can animate the tableView
...
}
_keyBoardWillHide = YES;
Let me know if that works for you.
Rather than avoid the notifications, you can set an NSTimer for 0.1 second to do your animations in one, and in the other, cancel the timer, that way if you get UIKeyboardWillHide and UIKeyboardWillShow both at once, you'll get a chance to cancel the timer. If you don't get both, the timer will reach zero and the animations will be carried out.
Consider using the UITextFieldDelegate protocol. The method textFieldShouldBeginEditing: will fire off before the notification and it will fire off everytime you go into the text field.

Iphone- How to resize view when call status bar is toggled?

I'm creating an iphone app with few elements inside the controller (e.g tab bar, uiview, uitoolbar, etc..). Everything works fine until I encountered this problem. While my application is launched, I received a call and it shows the "Call Status Bar" which ruined the ui. Some elements are pushed down because the "Call Status Bar" is taking space at the top.
Anybody here have an idea on how to fix this issue? I'm new to iPhone app development.
Your reply is greatly appreciated...
Best Regards,
dianz's solutio works just fine but is a bit redundant if you are only interested in knowing about the notification inside of a specific view controller.
After the delegate method application:didChangeStatusBarFrame: is called in the Application Delegate UIApplicationDidChangeStatusBarFrameNotification is posted through [NSNotificationCenter defaultCenter].
Instead of using the delegate method application:didChangeStatusBarFrame: to simply repost a custom notification you can add an observer to UIApplicationDidChangeStatusBarFrameNotification directly from your view controller.
In MyCustomViewController you would add something similar to this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doSomething:)
UIApplicationDidChangeStatusBarFrameNotification
object:nil];
Now you no longer need to define the application:didChangeStatusBarFrame: delegate method in appDelegate (unless you plan to do something in the appDelegate when the status bar changes size).
As with dianz's example you need to remove the observer in dealloc
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
You should put this function on appDelegate, this will trigger when the status bar change
- (void)application:(UIApplication *)application didChangeStatusBarFrame (CGRect)oldStatusBarFrame
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:#"trigger" forKey:#"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"trigger" object:self userInfo:dict];
}
This Code will send Notification with the name "trigger"
Place a code to your view Controller (e.g: viewDidLoad, etc..) this listen if there are notification send with a name "trigger"
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(dataReceived:)
name:#"trigger"
object:nil];
And create a function dataReceived:
- (void)dataReceivedNotification:(NSNotification *)notification {
NSDictionary *data = [notification userInfo];
// do something with data
}
do something on this part of the code, maybe you change the frame of your tab bar, uiview frame, toolbar frame
And in dealloc, put this code to remove the observer
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Basically what you normally do is try to set up the autoresize flags of all your ui elements in interface builder so that when the main view is "squashed" by the call status bar everything will still look reasonable. It's a little hard to explain how to do all of this in one message, but I recommend creating a view in IB, placing some subviews in it, then resizing the main view while playing with the autoresize flags to get a feel for how the flags work. The autoresize flags are in Command-3 (size inspector).
You can also set wantsFullScreenLayout in the main view controller to YES to cause the view to take up the whole screen, including the area under the status bar, but then you'll have to make sure not to place anything under the status bar and the call status bar will overlap anything too close to it, of course.
for me, whenever the status bar is enlarged, the -(void)viewWillLayoutSubviews is always called. This is perfect for me because all my subview setFrame code is in this function.