Fixed footer of a UItableview. always at the foote

2019-06-11 04:34发布

问题:

Im trying to have a footer Fixed at the bottom of a uitableview. it will always be at the bottom, not scrollable with the table cells. It also cant cut out and cells like cover the last cell of a uitable view so one cell will be hidden. I have the following header file:

//fooer contains a number_of_total_clicks label, an a proceedtopayment button. 
@interface checkout : UITableViewController

@property (retain, nonatomic) IBOutlet UILabel *number_of_total_clicks;
- (IBAction)proceedtonextview:(id)sender;
@property (retain, nonatomic) IBOutlet UIView *footer; //?
@property (strong, nonatomic) NSMutableDictionary *items_clicked;
@end

and in my .m file

- (void)viewDidLoad
{
    [super viewDidLoad];
    //self.tableView.tableFooterView= footer; ??
    number_of_total_clicks.text=@"0";
}

//void or IBAction?V
- (void)add_item_to_array_of_clicks_which_will_increment_number_of_total_clicks_value:(id)sender{
    number_of_total_clicks.text=[NSString stringWithFormat:@"$%.2f",[sender doubleValue]*5];
    [self.tableView reloadData];
}

What happens is I get a footer the is basically attached to the last cell of the table so if the table has only 3 cells, the "footer" with the number_of_total_clicks will be attached as a 4th cell. if there are 45 cells, he footer will be he 46th cell only accesible once I scroll all the way down. I want it o be fixed a the bottom. Thanks

回答1:

In your -loadView method try manually creating your view using [UIScreen mainScreen]. applicationFrame as the frame. Note that you should use a UIView, not a table view.
This view will fill the whole screen (except for tab and navbars, when using them).

You can then manually add a UITableView as the VC's tableView, but don't make it fill the whole view. Leave some space at the bottom, just as much to fit your 'table footer' in. Remember to set the tableView to have a flexible width as well as a flexible height.

Now for the 'table footer' just add it as a subview to self.view (not self.tableView) and place it at the very bottom of self.view. This view should have a flexible width and a flexible top margin.

I hope this fits your needs.