Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 706 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to disable floating headers in UITableView with UITableViewStylePlain?

#11
Another way to do it is to make an empty section right before the one you want the header on and put your header on that section. Because the section is empty the header will scroll immediately.
Reply

#12
I have another even simpler solution, to be used without autolayout and with everything done through the XIB :


1/ Put your header in the tableview by drag and dropping it directly on the tableview.

2/ In the Size Inspector of the newly made header, just change its autosizing : you should only leave the top, left and right anchors, plus the fill horizontally.

![That's how it should be set for the header][1]


That should do the trick !


[1]:
Reply

#13
In your Interface Builder click on your problem Table View

[![problem table view][1]][1]


Then navigate to Attributes Inspector and change Style Plain to Grouped
;) Easy

[![easy][2]][2]


[1]:

[2]:
Reply

#14
You can add one Section(with zero rows) above, then set the above sectionFooterView as current section's headerView, footerView doesn't float.
Hope it gives a help.
Reply

#15
There is another tricky way. The main idea is to double the section number, and first one only shows the headerView while the second one shows the real cells.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionCount * 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section%2 == 0) {
return 0;
}
return _rowCount;
}
What need to do then is to implement the headerInSection delegates:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section%2 == 0) {
//return headerview;
}
return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section%2 == 0) {
//return headerheight;
}
return 0;
}
This approach also has little impact on your datasources:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
int real_section = (int)indexPath.section / 2;
//your code
}

Comparing with other approaches, this way is safe while not changing the frame or contentInsets of the tableview.
Hope this may help.
Reply

#16
You should be able to fake this by using a custom cell to do your header rows. These will then scroll like any other cell in the table view.

You just need to add some logic in your `cellForRowAtIndexPath` to return the right cell type when it is a header row.

You'll probably have to manage your sections yourself though, i.e. have everything in one section and fake the headers. (You could also try returning a hidden view for the header view, but I don't know if that will work)
Reply

#17
**WARNING**: this solution implements a reserved API method. This could prevent the app from being approved by Apple for distribution on the AppStore.

I've described the private methods that turns of section headers floating in [my blog][1]

Basically, you just need to subclass `UITableView` and return `NO` in two of its methods:

- (BOOL)allowsHeaderViewsToFloat;
- (BOOL)allowsFooterViewsToFloat;

[1]:

[To see links please register here]

Reply

#18
Maybe you can simply make header view background transparent:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
view.tintColor = [UIColor clearColor];
}

Or apply it globally:

[UITableViewHeaderFooterView appearance].tintColor = [UIColor clearColor];
Reply

#19
The easiest way to get what you want is set your table style as `UITableViewStyleGrouped`,
separator style as `UITableViewCellSeparatorStyleNone`:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN; // return 0.01f; would work same
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
Do not try return footer view as `nil`, don't forget set header height and header view, after you must get what you desired.
Reply

#20
Maybe you could use `scrollViewDidScroll` on the tableView
and change the `contentInset` based on the current visible header.

It seems to work for my use case!

extension ViewController : UIScrollViewDelegate{

func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let tableView = scrollView as? UITableView,
let visible = tableView.indexPathsForVisibleRows,
let first = visible.first else {
return
}

let headerHeight = tableView.rectForHeader(inSection: first.section).size.height
let offset = max(min(0, -tableView.contentOffset.y), -headerHeight)
self.tableView.contentInset = UIEdgeInsetsMake(offset, 0, -offset, 0)
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through