如何删除 UITableView 中的空单元格? [英] How to remove empty cells in UITableView?

查看:25
本文介绍了如何删除 UITableView 中的空单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一些数据显示一个简单的 UITableView.我希望设置 UITableView 的静态高度,以便它不会在表格末尾显示空单元格.我该怎么做?

i am trying to display a simple UITableView with some data. I wish to set the static height of the UITableView so that it doesn't displays empty cells at the end of the table. how do I do that?

代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSLog(@"%d", [arr count]);
    return [arr count];
}

推荐答案

设置一个零高度的表格页脚视图(可能在你的 viewDidLoad 方法中),像这样:

Set a zero height table footer view (perhaps in your viewDidLoad method), like so:

斯威夫特:

tableView.tableFooterView = UIView()

目标 C:

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

因为表格认为有一个页脚要显示,所以除了您明确要求的单元格之外,它不会显示任何单元格.

Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.

界面构建器专业提示:

如果您使用的是xib/Storyboard,您只需将一个 UIView(高度为 0pt)拖到 UITableView 的底部即可.

If you are using a xib/Storyboard, you can just drag a UIView (with height 0pt) onto the bottom of the UITableView.

这篇关于如何删除 UITableView 中的空单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆