我按照此回答here中的说明操作并设法获取我的自定义UITableView标题部分:
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "TableSectionHeader", bundle: nil)
billTableView.register(nib, forHeaderFooterViewReuseIdentifier: "TableSectionHeader")
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = billTableView.dequeueReusableHeaderFooterView(withIdentifier: "TableSectionHeader")
let header = cell as! TableSectionHeader
header.lblPerson.text = array[section].name
header.lblTotal.text = "$0.00"
return cell
}
一切正常但是我需要一个分隔线用于各个部分,因为该部分是我的笔尖的UIView,我无法使用.separatorStyle
......
我需要添加一个分隔线,因为我想展开/折叠行。非常感谢你的帮助!
答案 0 :(得分:1)
也许您需要自己添加一个分隔符:
CGRect seperatorFrame = CGRectMake(0, headerView.frame.size.height-1, tableView.bounds.size.width, 1);
UIView *seperatorView = [[UIView alloc] initWithFrame:seperatorFrame];
seperatorView.backgroundColor = [UIColor grayColor];
[headerView addSubview:seperatorView];
或在.xib中使用Autolayout:
http://elixir-lang.org/getting-started/mix-otp/supervisor-and-application.html#supervision-trees