iPhone OS 3.2 (iPad) Modal View question - ipad

I am presenting a UIViewController as a modal viewcontroller with modalPresentationStyle = UIModalPresentationFormSheet. I have few UITextFields on its view.
My issue is that when I try to dismiss the keyboard ([textfieldname resignFirstResponder]), it doesn't do anything. However when I change the modalPresentationStyle to UIModalPresentationPageSheet, it works.
This seems to be a bug. Has any one faced similar problems and found a work around? Could I be doing anything dumb and silly?

I ran into this same issue with UITextView, I ended up subclassing UITextView and overriding resignFirstResponder as follows...
- (BOOL)resignFirstResponder{
[super resignFirstResponder];
// For some reason, UITextView doesn't like to give up first responder, ever....
return YES;
}
I haven't checked if this is still necessary in 4.3 but it was definitely needed in 3.2 in some cases.

Related

UIKeyboardAppearance broken: showing both styles at once

I have a UITextView with the keyboard appearance set to dark. But once I present and then dismiss a UINavigationController I get a keyboard like this:
Now I'm not sure what to do to get this back to normal? Once I dismiss the keyboard and show it again it is back to normal, however this is not acceptable.
I'm assuming this is an Apple bug, but does anybody know a way to get around this?
Thanks!
Ok, I figured out how to get around this bug. You simply have to dismiss the keyboard before you present the view controller. Like so:
[self.textView resignFirstResponder];
I'm not sure what causes this bug, but just case anyone else is having this problem, that's what I'm doing to fix it.

iOS 8.3 pushViewController shows empty view first, then view is shown

iOS 8.3 changed the behavior of pushViewController to show blank view first, then the view is shown. Any tips to fix this issue?
Same code on different iOS versions
iOS 8.3 broken behavior: https://vid.me/4JDf
iOS 8.2 expected behavior: https://vid.me/qgvA
The basic code that pushes the view:
[self.navigationController pushViewController:view animated:YES];
PS: The VC's code is under NDA, sadly I can not share it.
Please set background color for view.view any color except clear color
This seems like a layout clash issue in the new view. Commenting out some layout based code solved the issue. Basically we had more layoutIfNeeded than needed.
[self.view layoutIfNeeded];

Weird resignFirstResponder behaviour with UITextfield

I have a textfield that is on a modally presented viewController that is inside a navigation controller, when i use
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
the keyboard hides as expected when i push return, but for some reason the whole view that the textfield is in sort of shrinks to the top left and leaves all the subviews shifted to the left. its a really simple view so im not sure what is going wrong, is there a different way to hide the keyboard that could potentially avoid this problem?
here are some screenshots
ive attached the full code here: http://pastebin.com/PKMXEL4U
Ok wow, weirdest symptoms for such a silly mistake, turns out i forgot to put [super viewWillAppear:animated]; in the viewWillAppear it took me reconstructing the whole class and storyboard in a separate project to find that out >.<

UIPageViewController on UINavigationController does not relayout its child viewcontroller since changing orientation

I am making the following view controller(VC) structure.
[UINavigationViewController] -> [UIPageViewController] -> [UIViewControllers]
then, this VC should support portrait and landscape orientation.
A problem I have is raised at changing orientation to any sides.
you can see the problem.
red area is background color of child VC on UIPageViewController.
blue area is background color of UIPageViewController.
I guess child VC was not relayouted by UIPageViewController. I have figured it out for a long time. I finally ended up finding a work around to add the following overridden function to custom UIPageViewController.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self setViewControllers:self.viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:NULL];
}
Although moving a view to downside is showed as soon as finishing rotation. This code solves the problem roughly.
anyway, I really want to know any nice and natural solutions.
UPDATE
My app works well on iOS6. it may be iOS7 bug?
I have solved this problem to place the following SINGLE line of code in [viewDidLoaded] of custom UIPageViewController.
self.automaticallyAdjustsScrollViewInsets = NO;
I supposed that UIPageViewController has a scroll view, and if it is embedded in UINavigationController, it will lay out incorrectly since changing orientation.
Fortunately, my solution fitted in the problem.
#MirkoCatalano Thank you for your comments. these are very helpful to found out right solution.

Toolbar disappears when hiding keyboard

I have a nav controller with a toolbar. I made the toolbar also appear on top of the keyboard when the keyboard appears. When I dismiss the keyboard, the toolbar disappears, leaving a black rectangle at the bottom of the screen, just where the toolbar should be without the keyboard.
Here's how I init the toolbar:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:NO];
// this makes sure the toolbar appears on top of the keyboard
// instead of going below it.
// _nameText is a UITextField
_nameText.inputAccessoryView = self.navigationController.toolbar;
}
This is how I hide the keyboard:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self.navigationController setToolbarHidden:NO]; // this doesn't help
return NO;
}
I tried also doing [self.view setNeedsLayout], but that didn't work.
EDIT: I suspect this may have to do with the fact that I assign the toolbar to be the input accessory view of my text field. I think that the text field hides its accessory view when the keyboard goes away. I still don't know how to override that behavior though.
EDIT 2: I discovered that self.navigationController.toolbar.superview is nil after the keyboard is gone.
OK, so while I couldn't solve the problem head-on, I found an acceptable workaround.
Create a .xib for your toolbar
Load the toolbar from (1) into an object
assign that object to the inputAccessoryView property of your text field
set up the target and the actions for the buttons in this toolbar, so you can respond to clicks
You are now all set. Your original toolbar (which you presumably have created in the Interface Builder) is only visible when the keyboard is hidden. When the keyboard is visible, the original toolbar cannot be seen, but your other one (created with the steps described above) now appears above the keyboard. Bingo!
If anyone has a more elegant solution to this problem, I'd be happy to hear about it :)
#BlackRider, I ran into the same exact issue as you. It is quite annoying.
I didn't want to set up 2 different toolbars as a workaround, as I didn't want to handle the state of the toolbar buttons in 2 different places.
I've resorted to using the approach discussed here in the answer that uses notifications: iPhone: How to fix inputAccessoryView to View?
It's working ok - my gut reaction is that I'll run into issues when trying on various device sizes / orientations.

Resources