简体   繁体   English

在UITableView中更改自定义Section视图的标题

[英]Change Titles of custom Section view in UITableView

I have a UITableView with expand and collapse cells when I tap in the sections. 在各节中点击时,我有一个带有展开和折叠单元格的UITableView。 Now I want to collapse the cells again when I tap in one of this cells and give the name of this cell to the section up there. 现在,当我点击其中一个单元格并将该单元格的名称提供给上面的部分时,我想再次折叠这些单元格。 I think that collapse is not a problem but I do not know how to change the name. 我认为崩溃不是问题,但我不知道如何更改名称。 I have done everything programmatically. 我已经以编程方式完成了所有工作。 Thank you 谢谢

You can try like this: 您可以这样尝试:

  1. add an observer in custom section view to update title. 在自定义剖面视图中添加观察者以更新标题。 Because section view is reused in UITableView,need a parameter(such as: int sectionIndex) to definite witch section the section view belong to. 由于截面视图在UITableView中被重用,因此需要一个参数(例如:int sectionIndex)来确定该截面视图所属的截面。

  2. in tableView:viewForHeaderInSection: set sectionView.sectionIndex with indexPath.section 在tableView:viewForHeaderInSection中:使用indexPath.section设置sectionView.sectionIndex

  3. in tableView:didSelectRowAtIndexPath: post a notification with indexPath.section and title string 在tableView:didSelectRowAtIndexPath中:发布带有indexPath.section和标题字符串的通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM