Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UITableViewHeaderFooterView non sticky

I am having a common footer for all cells and I am setting it with

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

I know that by default footers are sticky to bottom of UITableView, I dont want footers to stick to bottom of table, what is best way to achieve this?

One way I know is to add extra row and show footer there, But I am looking for cleaner approach than this.

Can anyone help me with this?

like image 860
Abhishek Avatar asked Jan 09 '15 07:01

Abhishek


Video Answer


2 Answers

You can set UITableViewStyle as UITableViewStyleGrouped.

Use this initializer.

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

You can set this on storyboard.

enter image description here

like image 71
Ryan Avatar answered Oct 08 '22 05:10

Ryan


You can create an extra uitableviewcell and append at the last of tableview. In the numberOfRowsInSection: method you can add one 1 like

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

in tableView:cellForRowAtIndexPath: method

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
         if(indexpath.row  == [objectArray count]) {
          //create footer cell
        }
        else {
        //show normal cell
       }
    }
like image 23
Suhit Patil Avatar answered Oct 08 '22 04:10

Suhit Patil