のプロパティは、コンテンツUITableView
の下部、最後のセクションの下に常に表示されるオブジェクトです。それがAppleのドキュメントで本当に明確ではない場合でも(抜粋:「テーブルの下に表示されるアクセサリビューを返します。」)。tableFooterView
UIView
フッターを静的で非フローティングにしたい場合は、次の 2 つの簡単な選択肢があります。
- 理想的ではありませんが単純です: 最後のセクションのフッター ビューを静的フッターとして使用します。これはいくつかの条件で動作します:
- あなたの
UITableView
スタイルはUITableViewStylePlain
(セクションヘッダー/フッターにおよびとUITableViewStyleGrouped
同じ動作を与えるように)でなければなりませんUITableView tableHeaderView
tableFooterView
- 最後のセクション フッターを本来の目的で使用することはできません: 特定のセクションにフッター情報を提供する
簡単な例を次に示します。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = nil;
if (section == [tableView numberOfSections] - 1) {
// This UIView will only be created for the last section of your UITableView
view = [[UIView alloc] initWithFrame:CGRectZero];
[view setBackgroundColor:[UIColor redColor]];
}
return view;
}
- 現時点での最善の解決策: UIView を (コードまたは XIB のいずれかで) と同じレベルに追加します
UITableView
。ちょっとした条件:
- あなたの
self.view
所有物をあなたの物にしてUIViewController
はいけませんUITableView
。つまり、サブクラス化することはできませんUITableViewController
がUIViewController
、コントローラーUITableViewDataSource
をUITableViewDelegate
プロトコルに準拠させることができます。実際には、見た目よりも単純で、直接使用するよりも優れた実装です (私に関する限り) UITableViewController
。
コードの簡単な例を次に示します (ただし、Interface Builder を使用してもまったく同じことができます)。
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@end
ViewController.m :
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) UIView *fixedTableFooterView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGFloat fixedFooterHeight = 200.0;
// Initialize the UITableView
CGRect tableViewFrame = CGRectMake(CGRectGetMinX(self.view.bounds), CGRectGetMinY(self.view.bounds), CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - fixedFooterHeight);
self.tableView = [[UITableView alloc] initWithFrame:tableViewFrame style:UITableViewStylePlain]; // or Grouped if you want...
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];
[self.view addSubview:self.tableView];
// Initialize your Footer
CGRect footerFrame = CGRectMake(CGRectGetMinX(self.view.bounds), CGRectGetMaxY(self.view.bounds) - fixedFooterHeight, CGRectGetWidth(self.view.bounds), fixedFooterHeight); // What ever frame you want
self.fixedTableFooterView = [[UIView alloc] initWithFrame:footerFrame];
[self.fixedTableFooterView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:self.fixedTableFooterView];
}
- (void)viewDidUnload {
[super viewDidUnload];
[self setTableView:nil];
[self setFixedTableFooterView:nil];
}
@end
mask を指定UIViewAutoresizing
して縦向きと横向きでシームレスに動作させることもできますが、このかなり単純なコードを複雑にすることはしませんでした。
UITableViewDataSource
警告: この .h および .m ファイルは、必要なメソッドを入れていないため、コンパイルされません。setDataSource:
実際の動作を見たい場合は、その行をコメントしてください。
これが役立つことを願って、
その他細かいことでもお気軽にご相談ください