12

カスタムセルで UITableView を使用しています。
正常に動作していますが、UITableView にセルが 1 つまたは 2 つしかない場合に問題が発生します。
空のセルのセパレーターも提供しています。
カスタム セルで読み込まれるセルにのみセパレータを表示することはできますか?

4

3 に答える 3

26

テーブルから空の行を非表示にするには、空のフッター ビューを追加する必要があります。

迅速:

あなたのviewDidLoad()

self.tblPeopleList.tableFooterView = UIView.init()

目的 C:

最も簡単な方法:

あなたのviewDidLoad方法では、

self.yourTableView.tableFooterView = [[UIView alloc] initWithFrame : CGRectZero];

また

self.yourTableView.tableFooterView = [UIView new];

また

フッター ビューの外観をカスタマイズする場合は、次のようにできます。

UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.backgroundColor = [UIColor redColor];
self.yourTableView.tableFooterView = view;

//OR add an image in footer
//UIImageView *imageView = [[UIImageView alloc] initWithImage:footerImage.png]
//imageView.frame = table.frame;
//self.yourTableView.tableFooterView = imageView;

別の方法:

テーブルのデータソースメソッドを実装し、

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

同じことですが、テーブルに複数のセクションがある場合は、セクションごとに異なるビューを追加できます。この方法で、セクションごとに異なる高さを設定することもできます- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {...}

Objective-C Answer 注: この回答は iOS7 以降でテストされており、以前のバージョンでは各ケースをテストする必要があります。 Swift Answer 注: この回答は、iOS10.3 以降でテストされています。以前のバージョンでは、ケースごとにテストする必要があります。

于 2013-03-16T05:01:36.840 に答える
7

別の解決策:

UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.backgroundColor = [UIColor clearColor];
[self.tableView setTableFooterView:v];

これも効く

self.tableView.tableFooterView = [UIView new];
于 2013-12-18T03:22:52.790 に答える