在我的应用程序中,我有UITableView
5 个单元格数据。当我将运行该应用程序。它将在输出中正确显示 5 个带有数据的单元格。但是有很多额外的单元格显示为空。我想删除多余的单元格UITableView
。我也在 Objective-C 中做过,但我在 Swift 2.2 中需要一些帮助,而且我是 swift 的新手。
问问题
492 次
5 回答
5
在你viewDidLoad()
添加这一行:
yourtableView.tableFooterView = UIView()
或使用
yourtableView.tableFooterView = UIView(frame: CGRectZero)
于 2016-03-30T05:13:00.970 回答
1
试试下面的代码。可能这对你有帮助。
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
于 2016-03-30T05:42:02.507 回答
1
问题可能是由于您指定的行数UITableView
多于填充数据所需的行数。假设您正在UITableView
从一个数组填充,您可能应该将行数设置为数组的计数。
如果您使用UITableViewController
覆盖此方法
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
如果 aUITableView
嵌入到UIViewController
setUITableView
委托给 self 并实现此方法。
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
于 2016-03-30T05:20:19.470 回答
1
写这段代码
self.tableView.tableFooterView = UIView(frame: CGRectZero)
于 2016-03-30T06:25:30.020 回答
0
像这样实现这个委托方法:
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
于 2016-03-30T05:17:57.280 回答