UISearchController's UISearchBar shifts incorrectly and jumps when UITableView is scrolled - ios

In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg
I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).
SearchBar added like this:
let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search
When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).
I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.
If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.
What the reason of this behaviour and how to fix it?

I had the same problem with the search controller transition and tableview.
like this its flickering or tableview was jumping. The search controller was on the navigation item.
The key solution is to remove safe area guide from your view controller and assign top bottom left right constraints to your tableview. It will be smooth like this

What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.
Refer to this article. They have explained step by step process.

This is a known problem and your code seems fine. This problem was already discussed here.
Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.

Related

Buttons inside container view does not work

I am a total noob developing iOS applications and I'm working in one right now.
I have set up my storyboard with a HomeViewController (main) and inside this, a container view, with another view controller embeded. This child view controller is outside the bounds of the view, and when a click a button in my HomeViewController it gets animated to the top of my app, showing this child with a cool animation. Everything is right.
In my child view controller I only have 3 buttons, and when they are displayed on the screen with this little animation, they are not usable. They don't trigger the action of the button being pressed nor they get "highlighted" with iOS style. Nothing happens.
I have been searching a lot about this, I have tried addChildViewController() on parent, didMove(toParentViewController: UIViewController) on child and I also have added it programmatically. When added programmatically it works OK but the view does not respect the animation, just being displayed in the screen without following the parent's container, which indeed moves with the animation.
What should I do next?
Thank you very much
Edit: My question does not seem to be a duplicate of UIView animations canceling any touch input
I'm using Spring library for the animations. Also, in that thread they are talking about user interaction being blocked while animation isn't finished. That is not my case. Animation is perfectly finished when trying the button interaction.
From my experience, there are two issues which cause this behavior most often:
Some of your container views have userInteractionEnabled set to false, or
Your container view frame is small and you're attempting to tap a button outside the frame of the container which won't work. Consider it like a window to the button and there's an invisible wall blocking touches.
Both of these are best debugged using the Xcode Debug View Hierarchy, or you can also try the Reveal app and see what's going on there.
Finally, this misbehavior was because the wrapping view in my container was smaller than the container, but as these two were out of screen I didn't realise at first. Making the wrapping view big enough to fit the child container was the solution.
Sorry because at last this was a stupid question.
Thank you all
If you use auto layout. You may check out your constraint is correct or not. Especially for biggerOrEqual and smallerOrEqual constraint still need a concrete constraint. eg:
width = 100#750
width <= superView.width#999
You should not forget the first constriant.

TableView issue (weird Visualization)

I have a class (movieTable.m) with TableView populated with many cells.
As i Clicked one of them, the navigation controller brings in the other scene done in the StoryBoard.
When i get back, still with Navigation Controller, i find the TableView moved little bit down.
As I debugged the Hierarcy i found that UITableViewWrapperView is scrolled down from UITableView.
Edit: The funny thing is: if i put a UiSegmentedControl in the UiView the issue disappears.
Why this? i didn't tell the code to move it. Maybe I'm getting wrong with the timing?
so to making clear the ideas, there's two images:
Hierarchy before/after changing the scene
The Code if you want to see it is in this following GitHub: GitHub
Thank you all for helping&hints.
this worked for me
add
self.automaticallyAdjustsScrollViewInsets = NO;
to your viewDidLoad of the moveiTable.m

Table View with extra View. View keep resizing to maximum

I have a tableview, that is working fine. I have added a view to the top, so I can add some extra fields. I can't post images yet, so going to try and describe.
Navigation Bar
View
TableView
When I build it, it looks good.. However when I run or close the project and reopen I get this:
Navigation Bar
View
TableView
With the view taking up the complete page, pushing the TableView to the very bottom.
Any thoughts on why this is happening and how to fix it?? I can resize it back to the size I want using the size inspector, but it doesn't keep the value.
I have built a test project with the same screen layout and it works perfectly. I can't see what is different between the two projects is. Thanks
Yes, this was an auto layout problem.. After looking around the web, and trying various solutions I decided to use a view controller, and add my own tableview and tablefviewcell to that, along with my other labels and buttons. Once I built the methods the first time, I found this to be much cleaner solution, than attempting to mess around with the tableviewcontroller.

Disappearing UITextField text

The issue I am having is that text in a UITextField disappears every other keyboard tap on iOS. This issue has happened in multiple view controllers, but previously I have been able to resolve the issue by making the textfield taller, giving it more room to draw the text inside.
That solution is not working for this particular situation. I am using a custom font for my app, so I have used a subclass of UITextField for the text fields that automatically sets the custom font. I have tried reverting back to the basic UITextField, but this does not solve the problem.
I have also tried commenting out the delegate methods I've implemented in the problem view controller and this does not solve my issue. I don't really know what else to try, so I'm hoping someone else here can point me in the right direction. Here are the things I've discovered about my problem so far:
The text disappears and reappears with every key tap, though tapping the backspace button does not change the appearance/disappearance of the text (i.e. if tapping backspace when the text is visible, text is deleted normally. If tapping while the text is hidden, characters are deleted from the textfield's text, but the user can't see what's happening)
Text appears at the bottom of the textfield when it is visible and the textfield is the first responder
When a different text field becomes first responder, the text in the problematic text field will be drawn properly, centered vertically in the textfield, and always visible.
Making a textfield first responder when it has text in it already will cause the text to redraw and appear as if it is scrolling up/down within the textfield. The text will alternately be drawn centered in the textfield and "scroll" down out of view, or be drawn out of view and "scroll" up into view, resting at the bottom of the textfield.
The view controller only has problems in one of the two modes it is presented in. It is either presented modally as the root view controller of a UINavigationController, or it is pushed onto a modally-presented UINavigationController's stack as the navigation controller's third view controller. In the first case, where it is the root view controller, the textfields work perfectly fine and exhibit none of the strange behavior described above. The strange behavior occurs consistently in the second case.
A good example of this problem can be seen in the video posted in this similar question: UITextField text disappears on every other keystroke. The answers to the question itself are not useful and do not solve my problems.
EDIT
I've been successful in reproducing the issue that I was having before. It turns out that the issue was caused by adding a subview to the navigation controller's view, then removing it while a UITextField was in focus. If the subview is removed while the UITextField is not being edited, the bug will not occur.
In my case, a loading image was added as a subview to the navigation controller during a net call, and removed after the completion of said call. During this time, a UITextField would be active, which would cause the visual bug I describe above.
I've recreated the bug in a standalone example project I've uploaded here: https://www.dropbox.com/s/s4kc05vg1pwteeo/Funky%20TextField%20Tester.zip. Also note that if you tell the textField to become first responder in the viewDidLoad implementation for the view controller, this bug will occur right at the beginning and persist.
NEW QUESTION
It's easy enough for me to just avoid putting the loading view in the navigation controller's view, but doing so gives me a nice effect of having the loading view 'float' in the same position on the screen, whereas putting it into a view controller's view on a nav stack raises a bunch of visual issues (moving loading view position when view controller is pushed onto stack, loading view is obscured by other view controllers, etc.).
Is there any way to reproduce this kind of look without putting the view into the navigation controller's view, or perhaps a safe way to put it into the navigation controller's view without performing strange workarounds like stopping editing on all UITextFields in the duration of the subview's presentation?
I've got the same issue here, didn't have in a previous version.
thanks to your project I've test, I've found that the issue is coming from presenting a view controller embedded in a navigation controller with a translucent navigation bar.
I set opaque bar in the simulated metrics of the navigation controller I was presenting and no more issue with UITextField.
On my case at least, everything were resolved at the moment I set opaque bar for top bar in simulated metrics in InterfaceBuilder for my UINavigationController which embed a UIViewController I've wanted to present modally
Hope it will be the same for you as well.
I had a similar problem where the UITextField was showing the text fine but when I came back from the background it was not show the text and the textfield seemed to not respond. However, I noticed that it was actually accepting input. It just wasn't visible. Showing the view in xcode's debut mode revealed that the textfield had moved down and was layered under other views and not visible. In my case I disabled AutomaticallyAdjustScrollViewInsets to NO and the problem was cured!
I have this exactly same problem on two search bars and several UITextFields in my app. It seems to come and go inexplicably and happens across multiple device types in the simulator and on multiple real devices. Rebooting the actual phone seems to make the issue go away in an app that's been installed on the phone. I'm guessing this is an Apple bug...but I really have no leads and none of the solutions here seem to fix the issue.
UPDATE
Ok, I may have solved it...I have a login controller that is shown before this text field, and I've found that if I open the keyboard on that login controller (like I don't just pre-fill in the username and password) then this behavior occurs. But if I don't open the keyboard, then it's totally fine.
UPDATE 2 -- SOLVED!!
So it turned out that when the user or password textfield in the login controller were selected, one of them became the first responder. When the user hit Login and the view went away, those fields never resigned from being the first responder, so it put the keyboard in a state of flux for the rest of the app.
Having the text fields resign as the first responder like below in my login method solved the issue:
if (_emailTextField.isFirstResponder) {
[_emailTextField resignFirstResponder];
}
if (_passwordTextField.isFirstResponder) {
[_passwordTextField resignFirstResponder];
}
...do login stuff
I had same problem . I was using becomeFirstResponder method inside viewDidLoad. But then I felt that becomeFirstResponder should be inside ViewDidAppear because didLoad method renders whole view at that time there is no user interaction . actual user interaction starts after viewDidAppear so I moved becomeFirstResponder inside the viewDidAppear method and everything works fine now.
Previous
-(void)viewDidLoad{
[self viewDidLoad];
[self.textField becomeFirstResponder];
......
}
After
-(void)viewDidAppear:(BOOL)animated{
[self.loginTextField becomeFirstResponder];
......
}
It seems to be a quite common bug from Apple and people have solved it in many different ways.
I came across the same problem. After some trials, I found my case is because I hide the navigation bar when certain textField "didBeginEditing". Once this bug occurs, it occurs all around the app, not only in that controller.
I eliminated this bug by not hiding the navigation bar (which is not what I really wanted but had no choice).
Hope this will help someone. In a nutshell, this bug can happen for various reasons. Try to undo some change until the bug disappears then you know where exactly it comes from.
I had the similar problem on some of the UITextFields added on UIView and found that it was a bug created by myself not by apple . I am setting textfield.setContentScaleFactor on textFieldDidBeginEditing delegate.
[textField setContentScaleFactor:10.0];
Removing the above line and it works without doing any other stuff.
My View hierarchy ---> UIScrollview --> UIImageView --> UIView --> UITextField
Hope it helps anyone.
I had a similar issue. Solved it by resigning keyboard for a previous screen.
The previous screen had a textfield which has a keyboard type of Numpad. So before coming to the screen where textfield flickers, i called resignFirstResponder.
The EDIT from the Ziewvater's original question solved my problem. I had several textfields being loaded at runtime and whenever I'd navigated back, those views were disposed/removed and then it'd instantiate new textfields each time. After reloading once, it would be clear text, but after editing did end, the textfield.text property would be set and you could see the text.
var responder = View.FindFirstResponder(); //(i'm in Xamarin)
if(responder != null)
responder.ResignFirstResponder();
Doing this in the viewwilldisappear fixed my problem. THANKS!!!!!!!

UITableView tracking touches on wrong axis

I have a uitableview controller which is a subview to a view managed by a uiviewcontroller. nothing really out of the ordinary but the tableview tracks gestures on the wrong axis(only on device).
Basically you scroll up/down table doesnt do anything, and left/right scrolls table up/down. its super weird. i was hoping somebody has seen this before and maybe know what causes it?
Edit: heres a video
http://c.drunknbass.com/EB7m
at the end i am scrolling a uiscrollview that scrolls normally and is a child of the same uiviewcontroller.view
UIKit relies on there being a key window, and that window having a root view controller, to be able to correctly handle events, and forward them to your code. I suspect that perhaps one of those things is not set up correctly in your app. (Such that the device orientation isn't matching up with the visual orientation of your UI.)
Also note that prior to iOS 5, making one controller's view the child of another controller wasn't really supported by UIKit. It can be done, and mostly works, but you are going to have to manage the forwarding of all of your lifecycle events. (See the notes on controller containment in the docs, and the description of -automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers as well.)

Resources