重命名uitableview部分的标题

时间:2016-04-01 12:08:40

标签: ios swift uitableview

如何在titleForHeaderInSection之外的uitableviewcontroller上重命名标题?

3 个答案:

答案 0 :(得分:0)

您可以在不使用cellForRowAtIndexPath

的情况下执行此操作
  • 为标题自定义单元格创建动态数组第一个对象,然后为tableview单元格创建对象...依此类推
  • 草稿自定义单元格草稿
  • 当屏幕显示时,根据标题自定义单元格和表格视图对象使用reloadRowsAtIndexPaths()条件
  • 在标题自定义单元格的特定事件更改数组值处,然后使用reloadRowsAtIndexPaths()

所以它只会重新加载reloadData()中给出的索引,不需要PackageManager

答案 1 :(得分:0)

因此,根据问题声明更新标题而不重新加载或委托仅使用标签引用来更新部分的标题。

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView() //set the frame accordingly 
let label = UILabel() //set the frame accordingly
//make it global and use it reference for updating the title of the section
view.addSubview(label)
return view
}

我没有使用Xcode所以请验证只是粗略地编写代码

答案 2 :(得分:0)

// If only section 2 has a header
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return section == 2 ? updateHeader(section) : nil
}

func updateHeader(section: Int) -> CustomHeader {
    let header = (tableView.footerViewForSection(section) ?? tableView.dequeueReusableHeaderFooterViewWithIdentifier("customHeader")) as! CustomHeader

    // Set up your header

    return header
}

// Change text in header
let header = updateHeader(2).customLabel.text = "Your custom text"

只是一个小例子。请注意,当tableview重新加载时,它将更改回标头的默认设置。所以一定要在自己的代码中处理。