A UITableView tableFooterView property is a UIView object that always appears at the bottom of the content, below the last section. Even if this is not entirely clear in the Apple documentation (extract: "Returns the auxiliary view that appears below in the table.").
If you want the footer to be static and non-floating, you have two simple options:
- Not perfect, but simple: use the footer of the last section as your static footer. This will work under certain conditions:
- your
UITableView style should be UITableViewStylePlain (since UITableViewStyleGrouped gives the same behavior for section headers / footers as for UITableView tableHeaderView and tableFooterView - You wonβt be able to use the footer of the last section for your real purpose: providing footer information in a specific section
Here is a simple example:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = nil; if (section == [tableView numberOfSections] - 1) {
- The best solution right now: add a UIView (either to the code or to your XIB) at the same level as your
UITableView . One small condition:- The
self.view property of your UIViewController should not be your UITableView object. This means that you cannot subclass UITableViewController , but UIViewController and combine your controller with the UITableViewDataSource and UITableViewDelegate protocols. This is actually simpler than it sounds and a more efficient implementation (as far as I know) than using the UITableViewController directly.
Here is a simple example in the code (but you can do the same with Interface Builder):
ViewController.h:
#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @end
ViewController.m:
You can also specify a UIViewAutoresizing mask UIViewAutoresizing that it works smoothly in portrait and landscape orientation, but I did not complicate this rather simple code.
A WARNING. These .h and .m files will not compile since I did not apply the required UITableViewDataSource methods. Comment out the setDataSource: line if you want to see it in action.
Hope this helps,
Feel free to ask me about other details,
Zedenem
source share