Ios 重命名uitableview节的标题

Ios 重命名uitableview节的标题,ios,swift,uitableview,Ios,Swift,Uitableview,如何将uitableviewcontroller上的节标题重命名为titleForHeaderInSection之外的节标题?无需使用titleForHeaderInSection 使动态数组成为标题自定义单元格的第一个对象,然后是tableview单元格的对象。。。等等 标题的草稿自定义单元格 当屏幕显示时,使用cellforrowatinedexpath,条件根据表头自定义单元格和表视图对象 在特定事件中,更改标头自定义单元格的数组值,然后使用reloadRowsAtIndexPaths(

如何将uitableviewcontroller上的节标题重命名为
titleForHeaderInSection
之外的节标题?

无需使用
titleForHeaderInSection

  • 使动态数组成为标题自定义单元格的第一个对象,然后是tableview单元格的对象。。。等等
  • 标题的草稿自定义单元格
  • 当屏幕显示时,使用
    cellforrowatinedexpath
    ,条件根据表头自定义单元格和表视图对象
  • 在特定事件中,更改标头自定义单元格的数组值,然后使用
    reloadRowsAtIndexPaths()

因此,它将只重新加载
reloadRowsAtIndexPaths()
中给出的索引,而不需要
reloadData()

,以便根据问题语句更新标题而不重新加载,或仅使用标签引用更新章节标题

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
,所以请验证我只是粗略地编写代码

// 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时,它将更改回标头的默认设置。因此,请确保您在自己的代码中处理该问题。

为什么不想使用
TitleForHeaderInstruction
?我必须在viewdidload中触发的函数中重命名标题,但是TitleForHeaderInstruction在此之前被触发,对我来说毫无用处。或者我做错了什么?您可以尝试一件事,只需添加UIView和UILabel,使用标签引用来更新文件的标题section@BuntyMadan你能举个例子吗?据我所知,你想通过重新加载表格或代理调用来更新标题。正确的?因此,我的观点是在
viewForHeaderInSection
create
UIView
和add
UILabel
中,所以只需使用标签引用来更新标题,但tableview不是动态的,它是静态的。不管怎样,使用一些对象来创建静态数组,其中一些对象用于标题自定义单元格,另一些对象用于表格视图自定义单元格。使用reloadRowsAtIndexPaths()只能重新加载该特定索引。CustomHeader是什么?是
UITableViewHeaderFooterView
的子类。您也可以使用普通的
UIView
UITableViewCell
,但是您必须使用其他方法来获取标题。