when will [UIViewController disablesAutomaticKeyboardDismissal] be called? - iphone

any example for how to use this?
I can't understand the document.

This is only about a view controller presented using UIModalPresentationFormSheet. In that case, a text field resigning first responder will not cause the keyboard to be dismissed unless you override disablesAutomaticKeyboardDismissal to return NO.

The rest of the framework will call it at an undefined time before they need to know if the view controller in question disables automatic keyboard dismissal. Since your implementation of a UIViewController subclass (where you are meant to override it) should return either always YES or always NO, it doesn't matter when it's called.

Related

what's the events of getting and losting focus in a view controller

There are 2 forms in my program. When view controller A gets the focus and be active, view controller B will lost the focus and be inactive. Can anyone show me What the events are?
Thanks
Miken, it depends on what type of objects you are using for your "forms".
The simplest "form" to use is a UITextField, and in that case, events will be sent to your UITextField's delegate. In a lot of simple cases, you will designate the viewController that holds your UITextfield to be the UITextFieldDelegate. For more information on the methods that the delegate has, take a look at this: https://developer.apple.com/library/ios/documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html#//apple_ref/occ/intf/UITextFieldDelegate
In this case, when the text field gets the focus (ie the user clicks on the text field to edit it) the delegate methods:
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
will be called. I'm using this as a basic example, and not assuming too much here, but generally you should be looking into your "forms" delegate methods.

Stop automatic dismissal of keyboard on iOS/disablesAutomaticKeyboardDismissal not called

I would like to be able to have another control become the first responder yet keep the keyboard showing to the user.
I found disablesAutomaticKeyboardDismissal in UIViewController and overrode it but it never get's called (iOS 5.0)
Is there a reason this method would not get called? Is there another way to keep the keyboard showing even though it's not required by the first responder?
Though it felt a bit like a hack what I did was make override canBecomeFirstResponder on UIView to return YES and then implement the UIKeyProtocol
https://developer.apple.com/library/IOS/documentation/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html
But did nothing on key press. This way the keyboard stays open but the keys don't matter.

why override canBecomeFirstResponder?

I'm looking at TVAnimationGestures from WWDC 2010, and in the TableVieWController.m, they override canBecomeFirstResponder:
- (BOOL)canBecomeFirstResponder {
return YES;
}
Is there a reason they do this? I don't see this method called anywhere. Thanks.
So you can mark your question as answered...
They are using an UIMenuController within the sample, and in order to receive messages from that controller to your controller, you must make your controller the first responder (and accept becoming first responder via canBecomeFirstResponder.
This method is called by the Cocoa framework and not typically application to see if a controller should become the first responder. While I haven't looked at that specific example, it probably allows the table to be editable.
I needed to override canBecomeFirstResponder in a custom UIView so I could use a custom InputView and InputAccessoryView.
Custom Views for Data Input
I had to do it this way because if I used a UITextField or UITextView, a hardware keyboard would subvert the more limited on-screen keyboard.

UISplitViewController not calling view delegate method in ios 5

I noticed this symptom in iOS 5 - Create an UISplitViewController with ViewController 1 on the left and ViewController 2 on the right. Open the popovercontroller in portrait, then close the popovercontroller. Viewcontroller 1's viewWillDisappear/viewDidDisappear methods does not get call. But in iOS 4.3 viewWillDisappear/viewDidDisappear methods does get call.
Anyone aware of a explanation for this change in behavior?
Apparently automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers method of the UISplitViewController is set to return NO instead of YES. So subclassing UISplitViewController and overriding automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers to return YES solved the problem.
Cheers!
I tried this with the unmodified split view controller template (master-detail app, iPad only, no storyboard) and I can't confirm your observation. The appear/disappear callbacks are called, for both children of the split view controller.
So there must be something else happening in your app; our initial conditions are clearly not the same, somehow... Or we might not be talking about exactly the same callbacks at the same moments. There is a clear note in the documentation ("Message Forwarding to Its Child View Controllers") about how a split view controller forwards these callback messages.

UIViewController not receiving touchesBegan message

I have a pretty simple UIViewController. It's initialized with a view I've created in Interaface Builder, which contains only a UIImageView. When the user touches the screen, I want the touchesBegan message of UIViewController to get called. So, I override it and added some logging, but nothing has happened.
I haven't done anything "special" at all, as since UIViewController inherits from UIResponder, I expect this to work right out of the box. From what I understand UIImageViews have user interaction disabled by default, so I have enabled it, both via InterfaceBuilder and in my UIViewcontroller's viewDidLoad method (I have tied the UIImageView to an IBOutlet). I also am ensuring that userInteraction is enabled in the parent view in Interface Builder.
Anything else that I am forgetting here?
OK, I'm a dummy. It works fine. The problem was, I didn't realize I was sending a release message to the UIViewController without having retained it elsewhere first. So that was causing the problem.
It is hard to say what your problem is, I don't know what you mean by overriding it?
Make sure you are connecting the touchesBegan event with an IBAction in Interface Builder?
You must create a IBAction function to handle the event, and explicitly connect the even to the IBAction. It is not as simple as simply overriding a method.
Although you have the View tied to an IBOutlet, you need to connect the event using an IBAction, or else you won't get any of those events.
Please ignore the first answer. It is, in fact, as easy as overriding the method in the custom view. The most common reason for not receiving touchesBegan is the canBecomeFirstResponder method not being implemented. This is not an IB hookup, these are the standard methods for touch handling.