In my project,
In the view 'Top' side is for one UIView and below it a tableView. I want to show tableView to top when scrolled and hide the tableView.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.topView.isHidden = true }
Please give me solution for how to show tableView to top when tableView scrolled.
Below is the screenshot
[![enter image description here][1]][1]
in this view bottom is tableView and top is UIView.
Below is the storyboard screenshot.
The simplest solution is to set that topView as tableHeaderView.
self.tableView.tableHeaderView = topView
Now when you scroll the tableView topView will goes up with it. Also no need to implement scrollViewDidScroll now.
Select your tableview in your Controller of Storyboard
Select your TableView
Go to Attributes Inspector on the right panel of Utilities
Set Style to Grouped
Related
I want to hide the view above my table view when I scroll down and show it again when scrolling up. That kind of behavior is implemented in many apps. How can I manage to do that?
Hook the height constraint of the view above the table
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let viewY = scrollview.contentOffset.y
self.topViewH.constant = (viewY == 0) ? 200 : 0
self.view.layoutIfNeeded()
}
Problem: It is not recommended to put a tableView inside a scrollView (basically tableView itself is a scrollView). Both iOS and user will get confused how/where to scroll because of scroll inside a inside.
My solution: For your usecase, you can put your view (which you want to hide on scroll down and show on scroll up) in the tableview header itself.
I put a UIScrollView occupies the whole area of my controller's view. Then I added a UIView (yellow color) on UIScrollView:
In my controller code, I have set the height of my scroll view:
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView.contentSize.height = 1000
}
When I run it and scroll up on the screen, I see this:
How to make the yellow view component's bottom matches the bottom of scroll view?
From the information provided the only guess could be that you forgot to add layout constraints.
In case you did add them, please update the question showing your constraints.
I have some issues with header and section here. My view is below:
Custom navigation with transparent.
TableView frame = screen bounds, contentInset top = 64.
TableView with header clear color.
TableView has 1 section view (view has 3 tab).
When I scroll tableview, section keep under navigation (perfect), but cells are scroll from section to top screen. I want cells only scroll in section, not to top and under navigation bar.
Can I help me? Thank you so much.
This is because the table view clipsToBounds by default is false, which means it will be rendered outside the table view bounds.
A solution:
tableView.clipsToBounds = true
I have a button in a view which is in the footer of a tableview (UITableViewController). Why is the button stretching when I try to apply the following code to it?
And I apply the code:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Make footerview so it fill up size of the screen
// The button is aligned to bottom of the footerview
// using autolayout constraints
self.tableView.tableFooterView = nil
self.footerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.tableView.frame.size.height - self.tableView.contentSize.height - self.footerView.frame.size.height)
self.tableView.tableFooterView = self.footerView
}
I was following the answer on this question:
Add button on top of UITableViewController (Swift)
Thanks!
If you read the question (whose link you posted) carefully, you can see that he resizes the view to take up the rest of the screen that is remaining after your table. Your button is the same size as your view, that is why it is stretching up. You need to add constraints which bind your button to the bottom of the view but not the top. Because if you bind the top and the bottom both to the view it will stretch.
Here is the example.
1. When you do not bind the button to the top. Notice that in the constraints, I do not have any constraint that specify the top of the button.
When you bind your button to the the top of the view. In this, I set a constraint which bind the button top to the view top. It stretches my button to take up the whole space as the view(which is similar to your case)
Hope this helps. :)
I'm using auto layout to design tableview that uses full margins of the cells and it's working partially.
Also tableView separatorStyle is not working too
class HomeTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
First disable the features width any and height any of both the tableview and tableview cell.
click on pin for image view or view you are using as background of cell select all the constraint left,right,top & bottom.You are selecting left,top,bottom in image above you posted. Deselect the height and width you are showing in image above.
If you want to place the text vew or label or etc in right of the table view then select left,right,top and only height. This would definately solve your problem. i am unable to post the image since i didnt have 10 reputation.Hope it will solve your problem.
Now You can also follow these methods:
iOS - Custom table cell not full width of UITableView