Fixed footer of a UItableview. always at the footer position

家住魔仙堡 提交于 2019-12-08 09:45:29

问题


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.



来源:https://stackoverflow.com/questions/10215868/fixed-footer-of-a-uitableview-always-at-the-footer-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!