I have a UIViewController in my Storyboard and in that I have a UIView which contains a UITableView.
I added another small UIView into the top of the UITableView which contains some buttons and text.
Basically, when the run the app, the UIView which I have placed in the UITableView goes to the bottom of the UITableView for some reason.... It scrolls perfectly with the UITableView, but it stays at the bottom...
How can I get the inserted UIView to stay at the top of my UITableView and still scroll with the UITableView?
Thanks, Dan.
What you're describing is the table view header. You don't add it to the table directly, but rather, you assign it to the table's tableHeaderView property like this:
self.tableView.tableHeaderView = myHeaderView;
Or you can just drag and drop a view into the storyboard at the top of the table view above the first section.
Related
I am trying to achieve whatsapp style drag tableview to show custom view, here is the screenshot
but I am clueless how to show custom UIView on top of UITableView when UITableView is dragged down
You can place your UIView behind the table view, and have its height grow as you drag down. Where you read the scroll offset for your table views scroll delegate.
I want to fix the GADBannerView at the bottom of UITableView, the banner shows at the end of the table after scrolling.
Please see this link. It is not possible you have to use a tableview inside a view controller which is better, than you can add a view to view of uiviewcontroller and constrain it at the bottom of view because than tableview is separate view inside main view.
Original answer is below.
Add subview to tableview which doesn't scroll
I want to add buttons that are static (they do not scroll with the Tableview) above the Tableview, but below the navigation bar. As described in this question
How to place buttons above UITableView (and not in navigation bar)?
The answer seems to be just use a UITableView, but is there a way of doing it with using a UITableViewController? or you have to use a UITableView and just make it smaller and put buttons above?
You can add buttons in a tableView in any case: just use the HEADER of the tableView.
In details the property is tableHeaderView, and add a view on top of the table.
By the datasource of the tableView you can also return an headerView for any section.
Apple Documentation
I have a UITableView and below the custom cell (in IB) I have inserted a UIView. The UIView gets set to hidden when viewDidLoad() gets called and is only displayed when there is no data in the UITableView. This works great and servers my purpose.
The problem is that even when the UIView is hidden, the scrolling on the UITableView considers the view to be present. i.e. The vertical scroll with scroll well below the last cell, covering the area where the UIView exists - even though its blank and nothing is displayed.
I have tried to hide the UIView but this doesn't help either. How do I get the scroll to not extend to the area covered by the UIView?
Edit:
The image on the left is how IB looks. I have added a UIView as a subview of the TableView. The image on the right is the large scroll space below the last cell.
Expected behavior: When the view is hidden, the scroll view only scrolls until the last cell.
If your view is displayed only when there is no cells, you could just add it over your UITableView (or behind it if your UITableView's background is clear) and hide it when you have cells to display. Just be sure to add your view as a sibling of your UITableView and not as a child view of your UITableView.
I have a view controller with following layout:
Container View
UIScrollView
UITableView as a sub view of a UIScrollView
I have another UITableViewController in which I have a few rows and some methods when the row gets selected. Now I want to display this UITableview inside the UIScrollView. So I add the UITableView as a subview of UIScrollView. The table is displayed in the scroll view just fine, but when I tap in the scroll view to select the table's row, then row is being highlighted but the method is not getting called when the row is selected..
PBDashboardPickupTable *dashtable = [[PBDashboardPickupTable alloc]initWithNibName:#"PBDashboardPickupTable" bundle:nil];
[self.scrollView addSubview:dashtable.tableView];
Also I have set scroll view's delayContentTouches to YES and cancelContentTouch to NO from Interface Builder. Also userInteractionEnabled is set to YES... then why is the method not getting called when I tap the table view's row?
Apple specifically warns in the documentation to avoid putting a UITableView inside of a UIScrollView:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Since UITableView inherits from UIScrollView, I would suggest you add any additional views you need as a tableHeaderView, tableFooterView, or as custom cells in the table.