Make UITableViewHeaderFooterView non-personal

I have a common footer for all cells and I set it with

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

I know that by default, footers are sticky for the bottom of a UITableView, I don't want the footers to stick to the bottom of the table, what's the best way to achieve this?

One of the ways that I know is to add an extra line and show the footer, but I'm looking for a cleaner approach than this.

Can anyone help me with this?

+4
source share
3 answers

You can set UITableViewStylehow UITableViewStyleGrouped.

Use this initializer.

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;

.

enter image description here

+3

uitableviewcell tableview. numberOfRowsInSection: 1,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [objectArray count]+1 ;
 }

tableView:cellForRowAtIndexPath:

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
         if(indexpath.row  == [objectArray count]) {
          //create footer cell
        }
        else {
        //show normal cell
       }
    }
+2

If you have a static height for the footer and not changing contentInsets, you can try this (provided that the height of the footer is 44):

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -44, 0)
0
source

Source: https://habr.com/ru/post/1570554/


All Articles