如何在UITableView中删除空单元格? [英] How to remove empty cells in 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:
Swift:
tableView.tableFooterView = UIView()
Objective-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屋!