I am using a header view, not section header, with my UITableView. The documentation says that the header view sits on top of the table, but my header view scrolls just like a normal row. Is there a way to make the header view always visible at the top of the table?
You certainly did found the solution for this, but I'm posting it here for other people.
The table view header and footer views do scroll with the rest of the rows.
If you want them to have a fixed position on top, or bottom of the table view then you don't really need a header or footer view.
Just add your desired view as a sibling of the table view (subview of tableView's superView) and position it on top or bottom of the tableView.
The solution is to implement:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
for a fixed header view, not use the self.tableView.tableHeaderView (this one is scrollable).
Related
I need some clever hints here :)
I need to add a tool bar to my page containing a table view. If the table does not fill up the entire page I need the tool bar to be positioned at the bottom at the page but if the table is longer than the page I need the tool bar to be positioned at the end of the table.
What to do?! :/
Thanks a lot for any help,
Stine
Use the footer view of UITableViewDelegate....
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Simply return a view from this and it will be placed at the bottom of the specified section (either a single section or your last one).
Also use..
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
To tell the Table view the height of the view.
I have a table view with multiple sections. I want to display different section header titles and want to add a label on the right corner of each section at a right margin of 4px.
Can I implement both
- (NSString *)tableView:(UITableView *)iTableView titleForHeaderInSection:(NSInteger)iSection
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
to achieve this?
Only one of them will ever get called successfully. tableView:viewForHeaderInSection: will get precedence.
Define a view with a title label and another label that sits on the right corner and return it in tableView:viewForHeaderInSection: with the values set.
How is a basic footer set to a UITableView programmatically?
Just a centered text?
EDIT:
How can the bar color be set and the footer bar position fixed to the bottom of the screen or if the thumbs dont fill a screen, the footer isnt above the bottom of the screen.
viewForFooterInSection sets the section's footer. To set the table's footer, you want to set
self.tableView.tableFooterView = myCustomFooterView
where myCustomFooterView is something you setup elsewhere. You'd probably set that in viewDidLoad.
You can use UITableViewDataSource callback (just text):
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
Or UITableViewDelegate (any custom view you like):
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
The tableview, custom table header, and custom section headers are loaded from a NIB. The tableview is grouped.
When the view loads, the first section header doesn't show up. If I scroll down, the other section headers will appear at first, but will disappear as soon as the section above them touches the top of the screen.
If I scroll back up so that a disappeared section header is off the screen, then scroll back down, it will usually reappear.
The problem is fairly consistent but not entirely- sometimes I have to scroll up and down several times to get a header to reappear. Any ideas as to what could cause this?
I fixed it- I was using one UIView for 3 sections, changing the text appropriately then returning it. Creating separate UIViews in the NIB for each section fixed the problem. So I guess you can't do that.
Your custom views must be (or descend from) UILable or UIImageView objects. You may need to manually set row height for the headers to get custom views to load and display properly.
You should review the details in the UITableViewDelegate protocol.
Specifically, look at these methods:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Part of the discussion on the tableView:viewForHeaderInSection: method states:
This method only works correctly when tableView:heightForHeaderInSection: is also implemented.
in the screen shot below, there are UISegmentedControl in between grouped UITableViewCells...it seems. How does one add other controls in between grouped cells in a UITableView?
You could make the Segmented View the same size as 1 table cell. Dead Simple to do in Interface Builder.
Tables with multiple sections, and sections can have custom header and footer..
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; // custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default