Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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 使用Swift自定义表格视图的页眉和页脚_Ios_Swift_Uitableview - Fatal编程技术网

Ios 使用Swift自定义表格视图的页眉和页脚

Ios 使用Swift自定义表格视图的页眉和页脚,ios,swift,uitableview,Ios,Swift,Uitableview,我需要为我的tableview创建一个自定义标题。为此,我创建了一个UITableViewHeaderFooterView类型的类,但我无法在情节提要上选择tableview的标题来设置该类。如果是静态表标题,则会显示,但动态表看不到该标题。如何设置此设置 注意:我使用xcode 7.3.1 我正在尝试这样做,但是故事板: 有几种方法可以做到这一点。其中大多数是通过编程实现的,有些是通过故事板和程序实现的 所以这完全取决于你想如何实现它 我可以和你分享一个最简单的方法来定制你的页眉和页脚部分

我需要为我的tableview创建一个自定义标题。为此,我创建了一个UITableViewHeaderFooterView类型的类,但我无法在情节提要上选择tableview的标题来设置该类。如果是静态表标题,则会显示,但动态表看不到该标题。如何设置此设置

注意:我使用xcode 7.3.1

我正在尝试这样做,但是故事板:


有几种方法可以做到这一点。其中大多数是通过编程实现的,有些是通过故事板和程序实现的

所以这完全取决于你想如何实现它

我可以和你分享一个最简单的方法来定制你的页眉和页脚部分

如果你对故事板有很好的控制,试着创建一个

UITableViewCell 
现在按照您的需要装饰它,并在标识符名称中使用它作为重用单元

之后,使用此委托方法,我将共享一个目标C委托

        override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {


var headerView: SectionHeaderTableViewCell? = tableView.dequeueReusableCellWithIdentifier("SectionHeader")
  if (headerView == nil) {
    headerView = SectionHeaderTableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"SectionHeader")
  }
  headerView!.textLabel!.text = "Hello World"


            return headerView;

        }

现在对页脚执行同样的操作。

分享您的代码,并分享您在Stackoverflow上读到的类似问题。否则,您的问题很快就会被标记出来|在Xcode 8.3.3和Mac OS 10.12.4中,这对我来说不起作用。您忘了提到
SectionHeaderTableViewCel
l应该子类
UITableViewHeaderFooterView
不要忘记覆盖节中标题的方法高度,否则默认情况下不会看到任何内容,因为默认情况下返回0。因此,添加如下内容:
override func tableView(\utableview:UITableView,heightForHeaderInSection:Int)->CGFloat{return 60}
        override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {


var headerView: SectionHeaderTableViewCell? = tableView.dequeueReusableCellWithIdentifier("SectionHeader")
  if (headerView == nil) {
    headerView = SectionHeaderTableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"SectionHeader")
  }
  headerView!.textLabel!.text = "Hello World"


            return headerView;

        }