Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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
Ios UITableView-设置页脚和页眉-如何设置表格视图单元格的滚动_Ios_Swift_Uitableview - Fatal编程技术网

Ios UITableView-设置页脚和页眉-如何设置表格视图单元格的滚动

Ios UITableView-设置页脚和页眉-如何设置表格视图单元格的滚动,ios,swift,uitableview,Ios,Swift,Uitableview,我必须实现带有页眉和页脚视图的TableView。我已经实现了所有这些,但是当创建tableView时,页脚和页眉仍然停留在我的屏幕中 我希望我的页脚在表格视图最后一个单元格的底部,当我在表格视图底部向下滚动时,页脚会出现。 所以就像一个标题一样,当我向下滚动标题时,我会保持在表视图的顶部。有人能帮我吗? 我的代码: 包含tableView的控制器: @IBOutlet weak var tableView: UITableView! { didSet { let he

我必须实现带有页眉和页脚视图的TableView。我已经实现了所有这些,但是当创建tableView时,页脚和页眉仍然停留在我的屏幕中

我希望我的页脚在表格视图最后一个单元格的底部,当我在表格视图底部向下滚动时,页脚会出现。 所以就像一个标题一样,当我向下滚动标题时,我会保持在表视图的顶部。有人能帮我吗? 我的代码:

包含tableView的控制器:

@IBOutlet weak var tableView: UITableView! {
    didSet {
        let headerNib = UINib(nibName: SearchingHeader.headerID, bundle: nil)
        tableView.register(headerNib, forHeaderFooterViewReuseIdentifier: SearchingHeader.headerID)

        let cellNib = UINib(nibName: SearchingResultTableViewCell.cellId, bundle: nil)
        tableView.register(cellNib, forCellReuseIdentifier: SearchingResultTableViewCell.cellId)

        let footerNib = UINib(nibName: SearchingFooter.footerId, bundle: nil)
        tableView.register(footerNib, forHeaderFooterViewReuseIdentifier: SearchingFooter.footerId)
    }
}

extension SearchingViewController: UITableViewDelegate, UITableViewDataSource {

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

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: SearchingHeader.headerID) as! SearchingHeader
    header.objectForSearch = objectOfSearch
    header.addressOnSearch = addressOfSearch
    return header.contentView
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 132
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footer = tableView.dequeueReusableHeaderFooterView(withIdentifier: SearchingFooter.footerId) as! SearchingFooter
    return footer.contentView
}


func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 243
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: SearchingResultTableViewCell.cellId, for: indexPath) as! SearchingResultTableViewCell
    return cell
}
标题xib:


页脚的创建方式与此相同。

您可以将页眉视图移出tableview,您需要根据tableview中的单元格管理或计算在tableview中的调用。您需要管理tableview高度。当您减小tableview的大小时,页脚视图将自动与tableview合并。我不能将页眉或页脚放在表的外部。它们必须是表视图的一部分。必须通过标题。10倍于单元格和页脚。所有这些都必须像滚动视图一样。顶部的页眉和底部的页脚将页脚视图作为最后一个单元格,并保持页眉视图不变。或者您可以尝试将表格视图样式更改为组。组帮助我!!!非常感谢兄弟!!!!
class SearchingHeader: UITableViewHeaderFooterView {

/// OUTLETS ///
@IBOutlet weak var mapButton: EnhancedButton! {
    didSet {
        mapButton.setImage(Asset.Icons.icoMap.image, for: .normal)
        mapButton.imageColor = UIColor.white
        mapButton.cornerRadius = 5
        mapButton.backgroundColor = ColorName.mainTurquoise.color
    }
}
@IBOutlet weak var objectOfSearchingTextField: LocalizedTextField!
@IBOutlet weak var searchIconImageView: EnhancedImageView! {
    didSet {
        searchIconImageView.imageColor = ColorName.mainOrange.color
    }
}

@IBOutlet weak var collectionView: UICollectionView! {
    didSet {
        collectionView.layer.backgroundColor = ColorName.mainGrey.color.cgColor
        let cellNib = UINib(nibName: SearchFilterCollectionViewCell.cellId , bundle: nil)
        collectionView.register(cellNib, forCellWithReuseIdentifier: SearchFilterCollectionViewCell.cellId )
    }
}

/// PROPERTIES ///
static var headerID: String = "Header"

var objectForSearch: String? {
    didSet {
        setSearchParameters()
    }
}
var addressOnSearch: String? {
    didSet {
        setSearchParameters()
    }
}
/// METHODS
override func awakeFromNib() {
    super.awakeFromNib()
    setUpView()
}