Creating a UIView that sticks to bottom of UITableView
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!