Ath*_*uma 2 uitableview ios swift
我需要为我的tableview创建一个自定义标题.为此我创建了一个UITableViewHeaderFooterView类的类,但我无法在故事板上选择tableview的标题来设置类.如果它是一个静态表头,但它对动态表不可见.我该怎么做这个设置?
注意:我使用xcode 7.3.1
我正在尝试这样做,但是故事板:https: //github.com/jeantimex/ios-swift-collapsible-table-section
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterViewWithIdentifier("header") as! NovaListaTableViewHeader
header.titleLabel.text = sections[section].name
header.arrowLabel.text = ">"
header.setCollapsed(sections[section].collapsed)
header.section = section
header.delegate = self
return header
}
Run Code Online (Sandbox Code Playgroud)
有几种方法可以做到这一点.大多数是通过编程实现的,有些是通过故事板和程序实现的.
所以它完全取决于你如何实现它.
我可以与您分享最简单的方法来自定义页眉和页脚部分.
如果您对故事板有很好的控制权,请尝试创建一个
UITableViewCell
Run Code Online (Sandbox Code Playgroud)
现在根据需要装饰它,并在标识符名称中,SectionHeader现在将其用作重用单元格
之后使用此委托方法我正在共享一个客观的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;
}
Run Code Online (Sandbox Code Playgroud)
现在为页脚做同样的事情.
| 归档时间: |
|
| 查看次数: |
6236 次 |
| 最近记录: |