85

私には があり、UITableViewその中には 3 行しかありませんが、それらの 3 行を見ることができます。問題は空のセルです。そこに線が見えます。私はそれらの行を見たくありません。

これらの行を削除する方法はありますか?

以下は、私が探しているものの画像です。

画像リンク

4

16 に答える 16

147

Andrey Zの返信よりもさらに簡単です: UITableView クラスで偽の tableFooterView を作成するだけです:

self.tableFooterView = [UIView new]; // to hide empty cells

とスウィフト:

tableFooterView = UIView()

于 2013-01-22T14:35:32.420 に答える
89

UITableView以下のコード スニペットのいずれかを使用して、 の標準の区切り線を非表示にできます。カスタム セパレーターを追加する最も簡単な方法は、UIView高さ 1px のシンプルなものを追加することです。

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor clearColor]; // set color as you want.
[cell.contentView addSubview:separatorLineView];

また

    self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,370) style:UITableViewStylePlain];
    self.tblView.delegate=self;
    self.tblView.dataSource=self;
    [self.view addSubview:self.tblView];

    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
    v.backgroundColor = [UIColor clearColor];
    [self.tblView setTableHeaderView:v];
    [self.tblView setTableFooterView:v];
    [v release];

また

- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    // To "clear" the footer view
    return [[UIView new] autorelease];
}

また

また、 nickfalk's answerも確認してください。これも非常に短くて役に立ちます。また、この1行を試してみてください。

self.tableView.tableFooterView = [[UIView alloc] init];

確かではありませんが、iOS 5 以降、iOS 7 まで、私が確認したすべてのバージョンの iOS で動作しています。

于 2013-01-22T14:25:28.437 に答える
8

swift および iOS 9 の回答を更新しました。これは、.Plainさまざまなテーブルビューで機能します。

 tableView.tableFooterView = UIView()
于 2015-11-20T18:45:30.420 に答える
7

高さ 1pxUIViewのフッターとして透明にするとうまくいきます。tableView

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
v.backgroundColor = [UIColor clearColor];
[self.tableView setTableFooterView:v];
于 2013-01-22T14:25:38.230 に答える
6
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
于 2014-04-03T16:13:14.310 に答える
3

このコードを使用して、空のセルの区切り線を削除します。

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return 0.01f;
}

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

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}   
于 2013-11-22T04:37:34.153 に答える
0

ストーリーボードを使用している場合は、UIView をセルの下の UITableView にドラッグ アンド ドロップし、その高さを 0 に設定するだけです (iOS 8 プロジェクトでのみテスト済み)。

于 2015-02-06T13:01:35.033 に答える
0

テーブルビューをプレーンではなくグループ化するように設定できます-これにより、外観が少し変わりますが、少なくとも余分な行が削除されます.

私はこの正確な問題を抱えていて、最終的にグループ化されたビューに変更しました。ずっと良く見えます。

于 2015-07-22T11:57:23.600 に答える
0

これがあなたが探しているものだと思います。

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1.0f;
}
于 2015-06-04T07:53:40.173 に答える
0

cellForRowAtIndexPath の内部

let separatorLineView:UIView = UIView(frame: CGRectMake(0,0,self.tableview.bounds.width,0.5))
separatorLineView.backgroundColor = tableView.separatorColor
cell!.contentView.addSubview(separatorLineView)
于 2016-04-08T20:11:20.620 に答える