Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

ios - 消除UITableView下面的额外分隔符(Eliminate extra separators below UITableView)

When I set up a table view with 4 rows, there are still extra separators lines (or extra blank cells) below the filled rows. (当我设置一个包含4行的表视图时,在填充的行下面还有额外的分隔符行(或额外的空白单元格)。)

How would I remove these cells? (我该如何移除这些细胞?)

UITableView中额外分隔线的图像

  ask by RoundOutTooSoon translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Interface builder (iOS 9+) (界面构建器(iOS 9+))

Just drag a UIView to the table. (只需将UIView拖到表中即可。) In storyboard, it will sit at the top below your custom cells. (在故事板中,它将位于自定义单元格下方的顶部。) You may prefer to name it "footer". (您可能更喜欢将其命名为“页脚”。)

Here it is shown in green for clarity, you'd probably want clear color. (为清晰起见,此处以绿色显示,您可能需要清晰的颜色。)

Note that by adjusting the height, you can affect how the "bottom bounce" of the table is handled, as you prefer. (请注意,通过调整高度,您可以根据需要影响表格的“底部反弹”处理方式。) (Height zero is usually fine). ((高度零通常很好)。)

在此输入图像描述


To do it programmatically: (要以编程方式执行此操作:)

Swift (迅速)

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.tableFooterView = UIView()
}

Objective-C (Objective-C的)

iOS 6.1+ (iOS 6.1+)

- (void)viewDidLoad 
{
    [super viewDidLoad];

    // This will remove extra separators from tableview
    self.tableView.tableFooterView = [UIView new];
}

or if you prefer, (或者如果你愿意,)

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

Historically in iOS: (历史上在iOS中:)

Add to the table view controller... (添加到表视图控制器...)

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

and if necessary... (如有必要......)

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

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...