I have a table view in first view and it has search bar. From that, I select 1 cell and it will push another view. After that, I come back to my first view and my search bar frame become zero like this. As a result, I can't see search bar but I can still tap on that. In visual debugging, I can still see search bar but on device, it disappear. May I know how it happen like this?
Related
I would like to use a UISearchBar and put it towards the bottom of a screen in order to search for available names through an API call. I want to have this SearchBar as part of a sign up form. However, when I put the SearchBar on the screen where I would like through the Storyboard, it does not show up when I run the app on the simulator. When I looked up this issue, everyone is putting the searchbar in a tableview. Am I not using the correct UI element for my cause?
The reason your search bar is not on the screen is probably because you didn't set constraint correctly or it was hidden or covered by some other view.
And for your second half of the question, I myself never put a search bar on a UITableView itself. Some apps put a search bar on the first cell of a table view but you have to scroll to make it show up. I myself always prefer to put it on the navigation controller on the top of the screen so that it will always be there and ready for user to search anything.
The current setup I have is a UIView over a map view that's meant to encapsulate the search bar (to make it look rounded). However, the first time I click on the search bar, it animates over the view for some reason, and then goes back to normal, but every other time, the animation stays within the view. The images below visualize the problem. I'm not entirely sure how to get started on fixing this -- any tips?
I instantiate the search bar and search results controller programmatically.
normal view (search bar not clicked)
the first time you click on the search bar vs every other time you click on it
I think you need to add constraints to fix this issue. And if possible try adding your search bar inside a UIStackView and then add constraints to the stack view.
I encountered an issue which I can't explain to myself and I hope that you can point me in the right direction or even provide me suitable solution.
I have a UITableViewController embedded in a UINavigationController with a custom prototype UITableViewCell. In my Storyboard, I added a Segue to show (push) a detail view controller onto the stack. This works fine and nothing is unexpected so far.
However, when I press the back button on my detail view controller, it goes back to my UITableViewController but this time, the TableView jumps to the top and reveals the TableViews HeaderView in which I put a SearchBar.
This happens when I check the "Hide Bottom Bar on Push" on my detail view controller, which I need so that the detail view controller hides the tab bar from the UITabBarController in which I embedded the NavigationController.
My hierarchy looks something like this:
-UITabBarController
--UINavigationController
---UITableViewController (my table view controller)
--(more view controllers for other tabs)
The strange thing is that this does not happen immediately. When I go back, at first everything looks good but then after a very short time it really jumps to the very top of the tableview.
I logged the table views contentOffset and its like this after I press the back button:
T0.000: viewDidLayoutSubviews => -20
T0.011: viewWillAppear => 44
T0.023: viewDidLayoutSubviews => -20
T0.530: viewDidAppear => -20 (correct value, same as before the push)
T0.540: viewDidLayoutSubviews => -64 (wrong value, showing search bar)
What does happen after round about half a second? Why does it suddently jumps to the top? I never set the offset by myself. It is somehow done automatically by the system and if I uncheck the "Hide Bottom Bar on Push" in my detail view controller, the behaviour is working as expected meaning if I had the search bar visible before, it is visible after and if it was hidden before, its still hidden after.
Well, I couln't find out how to fix this but at least I found a workaround to stop the jumping. I observed the same issue in other apps and even apple doesn't hide the search bar on app start anymore. Maybe because of this issue, who knows? So here is my solution.
First, this issue only happens if your table view has less cells than it would need to fill the whole screen. As soon as you have more cells than can fit on screen, after going to the detail view and then back to the master view, the tableview does not jump and stays at the very same position.
With this knowledge, I was able to create a workaround. My workaround is rather simple. I use segues to show various parts of my app so in my UITableViewController which is the "master", in prepare(for segue:sender:), before I show the detail view, I check if the first cell of the table view is visible. If so, I scroll the tableview to show the search bar.
if let firstCell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) {
if tableView.visibleCells.contains(firstCell) && !searchController.isActive {
let offset = CGPoint(x: 0, y: -tableView.contentInset.top)
tableView.setContentOffset(offset, animated: true)
}
}
When clicking one of the cells, a segue to show the details of the entry is performed. If the first cell is visible, i scroll the tableview down a little bit to show the search bar.
A better approach might be to actually calculate how many cells can fit on the screen and how many cells we have in total so we really only show the search bar when there are not enough cells but I found that this solution is good enough for me since it prevents jumping.
I have a pretty unique problem. I have a custom nav controller (https://github.com/cwRichardKim/RKSwipeBetweenViewControllers) and I'm trying to customize it even further. The effect I'm trying to get is this:
What I have is this (ignore the search bar):
The problem that I have is that when you click on any of the tabs in my nav bar ("public" for example), the click doesn't register, and it clicks whatever is underneath instead. For example, if I click "Munchies", it will click the search bar underneath the tab. Also, even if there is nothing clickable underneath it (I've tried this with a blank UIViewController), the tabs (eg: "Munchies") are still not clickable.
I have a theory for why this is. If I raise the tabs by a few pixels, the tops of the tabs become clickable. So, I think the navigationBar has a frame within which you can interact with its objects, but if you interact with anything outside of that frame, it interacts with lower layers. I've tried expanding the nav bar height and it doesn't work (I've looked it up and it's against the rules).
Any thoughts?
Thanks!
I read your code here that is shown here:
https://github.com/cwRichardKim/RKSwipeBetweenViewControllers/blob/master/RKSwipeBetweenViewControllers.m
I'm not exactly sure whether this will work out. But this issue has occured to me in table cell as well. Perhaps you can try typing this in.
[navigationView setUserInteractionEnabled:NO];
I'm pretty sure that your approach is on the right track because as I read Apple documentations it says:
Custom views can contain buttons. Use the buttonWithType: method in UIButton
class to add buttons to your custom view in the style of the navigation bar.
Custom title views are centered on the navigation bar and may be resized
to fit.
Hei guys.
What I am trying to achieve is have my search bar behind the navigation controller just like in the sparrow app. So when you scroll down the search bar is basically part of the view.
The first picture is the view when it's first loaded. The second one is after I scrolled down.
Do you know any way I can achieve this? I was thinking of having the search bar as part of the view and just load the view form the point that's just under the search bar. But I don't know how to do that. Any help would be much appreciated. Thanks.
I agree with #holex's comment if you're using a tableview. Seems silly to re-implement.
However, in the unlikely event you're not. You could just use a UIScrollView for your content and place the search bar at the top, and adjust the content offset accordingly. So it would appear as if the search bar has animated from under your navigation bar.
Here's a link to the UIScrolView class page on the dev site