Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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 UITableViewController节页眉和页脚不显示_Ios_Swift_Uitableview - Fatal编程技术网

Ios UITableViewController节页眉和页脚不显示

Ios UITableViewController节页眉和页脚不显示,ios,swift,uitableview,Ios,Swift,Uitableview,Swift 3,XCode 8.3 动态原型单元。视图(classCustomTableViewController:UITableViewController)位于一个单独的故事板中,该故事板从另一个故事板引用,其中一个片段从一个表中提取,该表本身嵌入在导航控制器中 实施以下方法: override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat over

Swift 3,XCode 8.3 动态原型单元。视图(class
CustomTableViewController:UITableViewController
)位于一个单独的故事板中,该故事板从另一个故事板引用,其中一个片段从一个表中提取,该表本身嵌入在导航控制器中

实施以下方法:

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
如果我在navcontroller中嵌入viewcontroller,
ViewForFooterInstitution
将被调用,并且视图将可见<代码>willDisplayHeaderView仍未调用编辑:它不是嵌入,而是将我的CustomTableViewController设置为初始视图控制器。当Nav控制器为IVC时,调用ViewForFooterInstitution,当CustomTableViewController(嵌入Nav控制器)为IVC时,不调用ViewForFooterInstitution

若我将表格更改为静态单元格,
willDisplayHeaderView
将被调用,
viewForFooterInSection
将被调用,但仅当视图嵌入Nav控制器时才会再次调用


嵌入另一个导航控制器会产生副作用,我正试图避免,但在任何情况下都不会调用
willDisplayHeaderView

您忘记了这些代理:

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

override func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
    return 100
}

标题也一样。快乐编码

您忘记了这些代理:

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

override func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
    return 100
}

标题也一样。快乐编码

为添加代理方法

  • 收割台高度(返回收割台的适当高度)
  • 标题视图
  • 页脚高度(返回页脚的适当高度)
  • 页脚视图

  • 如果您使用的是Viewcontroller中的表,请选中“委托”和“数据源已分配给表”。

    为添加委托方法

  • 收割台高度(返回收割台的适当高度)
  • 标题视图
  • 页脚高度(返回页脚的适当高度)
  • 页脚视图

  • 如果您使用的是Viewcontroller中的表,请检查是否将委托和数据源分配给表。

    您可以实现以下表视图方法

    extension DemoViewController: UITableViewDelegate {
    
    //setting header height to 100
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 100
    }
    
    //setting footer height to 100
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 100
    }
    
    //setting header view
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
        headerView.backgroundColor = UIColor.red
        return headerView
    }
    
    //setting footer view
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
        footerView.backgroundColor = UIColor.green
        return footerView
    }
    
    func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
        //customization for footer goes here
    }
    
    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        //customization for header goes here
    }
    }
    

    您可以实现以下表视图方法

    extension DemoViewController: UITableViewDelegate {
    
    //setting header height to 100
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 100
    }
    
    //setting footer height to 100
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 100
    }
    
    //setting header view
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
        headerView.backgroundColor = UIColor.red
        return headerView
    }
    
    //setting footer view
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
        footerView.backgroundColor = UIColor.green
        return footerView
    }
    
    func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
        //customization for footer goes here
    }
    
    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        //customization for header goes here
    }
    }
    

    我想我已经清楚地说明了这些方法是可以实现的,但是如果没有嵌入Nav控制器中,则不会调用ViewForFooterInstitution。当使用单元格的动态原型时,不会调用willDisplayXXXX。我想我已经清楚地说明了这些方法是实现的,但是当不嵌入Nav控制器时,不会调用ViewForFooterInstruction。当使用单元格的动态原型时,不会调用willDisplayXXXX。它是一个类CustomTableViewController:UITableViewController。。。是,正确分配了代表。当嵌入Nav控制器时,至少调用了ViewForFooterInstruction…它是一个类CustomTableViewController:UITableViewController。。。是,正确分配了代表。当嵌入Nav控制器时,至少调用了viewForFooterInSection…这是一个内部错误,实现了不相关的框架。实现所需的方法是可行的。这不是一个问题。这是一个内部错误,实现了不相关的框架。实现所需的方法是可行的。这不是问题。