Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何通过更改单元格高度创建动态TableView页脚_Swift_Uitableview_Footer - Fatal编程技术网

Swift 如何通过更改单元格高度创建动态TableView页脚

Swift 如何通过更改单元格高度创建动态TableView页脚,swift,uitableview,footer,Swift,Uitableview,Footer,我想创建一个页脚,它与tableview单元格的高度成动态关系 我最初的情况是: 如果我单击一行,它会将此单元格的高度更改为194(之前为44) 它不会显示所有行 如果我得到页脚-150,它看起来像: 如果我关闭所有单元格,它看起来像,我在页脚处用-150得到的150在这里是白色的: 我的代码: var selectedCellIndexPath: Int? let selectedCellHeight: CGFloat = 194.0 let unselectedCellHeight:

我想创建一个页脚,它与tableview单元格的高度成动态关系

我最初的情况是:

如果我单击一行,它会将此单元格的高度更改为194(之前为44)

它不会显示所有行

如果我得到页脚-150,它看起来像:

如果我关闭所有单元格,它看起来像,我在页脚处用-150得到的150在这里是白色的:

我的代码:

var selectedCellIndexPath: Int?
let selectedCellHeight: CGFloat = 194.0
let unselectedCellHeight: CGFloat = 44.0
var cellsHeight = [44, 44, 44]

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.beginUpdates()
    if selectedCellIndexPath != nil && selectedCellIndexPath == indexPath.row {
        selectedCellIndexPath = nil
    }
    else {
        selectedCellIndexPath = indexPath.row
    }
    if selectedCellIndexPath != nil {
        tableView.scrollToRow(at: indexPath, at: .none, animated: true)
    }
    tableView.endUpdates()
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    let rowHeight:CGFloat = 44
    var rowsHeight:CGFloat = 3 * rowHeight
    /*for i in 0..<cellsHeight.count {
        rowsHeight += CGFloat(cellsHeight[i])
    }*/
    let topHeight = UIApplication.shared.statusBarFrame.height + self.navigationController!.navigationBar.frame.height
    let viewHeight = self.view.frame.height
    let headerHeight:CGFloat = 30
    let height = viewHeight - topHeight - rowsHeight - headerHeight //- 150

    return CGFloat(height)
}

要对此进行存档,只能使用单元格,而不能使用页脚视图

步骤1:删除页脚视图

步骤2:添加日期选择器的单元格

步骤3:单击开始和结束日期时间单元格,然后在所选单元格下方插入日期时间单元格并重新加载表视图

第4步:希望这能解决您的问题

如果您有任何疑问,请告诉我

编辑:根据讨论,您只需使用tableFooterViewForSection删除额外的单元格分隔符

因此,您只需添加以下行即可解决您的问题:

tableView.tableFooterView = UIView(frame: CGRect(x:0, y:0, width:tableView.frame.width, heigth:0))
并删除
func tableView(tableView:UITableView,heightforfootensection节:Int)->CGFloat
方法


希望它能帮助您。

如果我理解正确,我应该为选择器创建3个额外的单元格,并在我单击的单元格下方显示一个?否。您使用的是静态还是动态单元格原型?动态单元格原型确定,那么您只需要为日期时间选择器创建一个单元格。当你点击任何单元格时,通过改变选择器对象在数组中的位置来重新排列单元格,并重新加载表格视图。这和改变点击单元格的高度一样吗?我不知道你的详细意思。。
tableView.tableFooterView = UIView(frame: CGRect(x:0, y:0, width:tableView.frame.width, heigth:0))