I have a grouped UITableView
and I'd like to add a UIButton to the very bottom of my UITableView
. I'm using Storyboard and a UITableViewController. I'm not quite sure where I need to add code or drag/drop UI Elements. I've tried adding a UIView as the footerview in Storyboard and then adding a button to that view, but this doesn't have the desired effect of always staying on the very bottom of the view, similar to a tabbar. Also, the button should always stay in the forefront, and the UITableView should scroll behind it.
// tried this but it didn't work:
self.tablview.tableFooterView = [[UIView alloc] initwithview...]
Make Footer Sticky To make your footer stick to the bottom of the viewport, add classes d-flex , flex-column , and h-100 to the body tag. Also add class h-100 to <html> tag.
There is one way you can use contentView property of UITableViewCell which of type UIView . So simply get RestaurantTableViewCell as you previously getting from nib then use its contentView to get the UIView from it.
If you want your UIButton
to be at the bottom of the screen regardless of the scroll position of the UITableView
(i.e., not inside the UITableView
) then you should probably not use a UITableViewController
subclass. Instead, if you use a UIViewController
subclass, you can simply add a UITableView
to your root view
property and add a UIButton
or some other view (such as a UIToolbar
, etc) with appropriate layout constraints to place it at the bottom of the screen - or wherever you want it. This is not really possible with a UITableViewController
subclass, as the root view
property is required to be a UITableView
instance.
OK, If you want to add the toolbar straight to the UITableViewController, you could follow the instructions in this tutorial to create a "fake" footer view.
If you are interested in being quick and easy, follow the answer giver above by @CharlesA, but it would probably look nicer if you used a standard toolbar with a UIBarButtonItem instead of just a Round Rect Button.
If you are using a Navigation Controller, then you can just unhide you toolbar (because the Navigation Controller comes with one already), and add a button to do what you need. Coding would be like this:
[self.navigationController setToolbarHidden:NO];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle: @"Button Name"
style: UIBarButtonItemStyleBordered
target: self
action: @selector(yourMethod:)];
self.toolbarItems = [ NSArray arrayWithObjects: buttonItem, nil ];
IMO the way to do it is create a UIViewController
instead of a UITableViewController
. Add a TableView
to the VC, raise the bottom of the TableView enough to fit a toolbar under there, drag and drop a toolbar, drag and drop a UIBarButtonItem onto it. Control-click from the UIBar button item and create your IBAction
.
Quick, simple, pretty.
There is one way to add views to the bottom of UITableViewController without using a UIViewController subclass.
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, footerY, footerWidth, footerHeight)];
[self.navigationController.view addSubview:footerView];
Hope this help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With