IOS swift可以消除TableView中未使用的行

时间:2016-12-08 03:22:24

标签: ios swift uitableview swift3

我正在使用swift 3.0并且其中包含TableView。一切都很顺利,但我现在只有2 rows返回,但TableView显示的是其他空白行。我想知道是否有办法消除这些行?

下面是我的简单应用程序现在看起来如何:正如您所看到的,我有2 rows并且我想要消除其他行,因为它们不需要在那里。我是TableViews的新手,我认为这段代码控制了应该出现的行数:

 func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
   return 2
 }

任何建议都会很棒

My TableView

4 个答案:

答案 0 :(得分:3)

tableView.tableFooterView = UIView()

答案 1 :(得分:2)

UIKittableView下方显示footerView时,

table cells不会创建空行。您可以使用zero height添加一个,以便用户看不到它。在tableView的viewDidLoad方法中。创建一个带有zero rect frame的新UIView并使用它来设置tableView的tableFooterView属性:

yourTableViewName.tableFooterView = UIView(frame: CGRect.zero)

答案 2 :(得分:1)

将页脚设为UITableView 从中删除所有空行或额外行。

on viewDidLoad()放在代码下面

Swift 3.0

yourTableViewName.tableFooterView = UIView()

答案 3 :(得分:1)

只需在viewDidLoad()上添加以下代码:

self.tblViewObj.tableFooterView = UIView()