2017-04-22 70 views
0

我跟着从这个答案here的指示,设法让我自定义的UITableView标题部分,像这样:如何添加自定义UITableView标题部分笔尖的分隔线?

enter image description here

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 ...

enter image description here

我需要添加分隔线,因为我想展开/折叠行。非常感谢您的帮助!

回答

1

也许你需要自己添加一个分隔符是这样的:在的.xib

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

+0

嗯,它的工作原理,但只有当我滚动了起来,向下,而不是在插入部分时。我把你的代码放在'viewForHeaderInSection'委托中。我应该在哪里插入这段代码,以便在插入节时添加分隔符? – iamhx

+0

如果您使用xib,您可以尝试拖动UIView(seperatorView)并配置AutoLayout。 – isaced

+0

是的,我正在使用xib。我不知道配置自动布局意味着什么..你能解释一下吗?谢谢! – iamhx