Ios 如何在tableview swift 2.2中以编程方式隐藏或删除额外的单元格和分隔符
在我的应用程序中,我有一个带有5个单元格数据的Ios 如何在tableview swift 2.2中以编程方式隐藏或删除额外的单元格和分隔符,ios,swift,uitableview,swift2.2,Ios,Swift,Uitableview,Swift2.2,在我的应用程序中,我有一个带有5个单元格数据的UITableView。我什么时候运行应用程序。它将显示5个单元格,输出数据正确。但还有很多多余的单元格显示为空。我想删除UITableView中的额外单元格。我在objective-C中也做过,但我需要在Swift 2.2中得到一些帮助,而且我是Swift新手。在您的viewDidLoad()中添加这一行: yourtableView.tableFooterView = UIView() 或使用 yourtableView.tableFoote
UITableView
。我什么时候运行应用程序。它将显示5个单元格,输出数据正确。但还有很多多余的单元格显示为空。我想删除UITableView
中的额外单元格。我在objective-C中也做过,但我需要在Swift 2.2中得到一些帮助,而且我是Swift新手。在您的viewDidLoad()中添加这一行:
yourtableView.tableFooterView = UIView()
或使用
yourtableView.tableFooterView = UIView(frame: CGRectZero)
在viewDidLoad()中添加以下行:
yourtableView.tableFooterView = UIView()
或使用
yourtableView.tableFooterView = UIView(frame: CGRectZero)
按如下方式实现此委托方法:
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
按如下方式实现此委托方法:
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
问题可能是由于在UITableView
中指定的行数大于填充数据所需的行数。假设您是从数组填充UITableView
,您可能应该将行计数设置为数组的计数
如果您使用的是UITableViewController
,请覆盖此方法
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
如果UITableView
嵌入到UIViewController
中,则设置UITableView
委托给self并实现此方法
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
问题可能是由于在UITableView
中指定的行数大于填充数据所需的行数。假设您是从数组填充UITableView
,您可能应该将行计数设置为数组的计数
如果您使用的是UITableViewController
,请覆盖此方法
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
如果UITableView
嵌入到UIViewController
中,则设置UITableView
委托给self并实现此方法
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
请尝试以下代码。也许这对你有帮助
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
请尝试以下代码。也许这对你有帮助
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
编写此代码
self.tableView.tableFooterView = UIView(frame: CGRectZero)
编写此代码
self.tableView.tableFooterView = UIView(frame: CGRectZero)