Expand/collapse section in UITableView in iOS(iOS UITableView 中的展开/折叠部分)
问题描述
Could somebody tell me the way to perform UITableView
expandable/collapsible animations in sections
of UITableView
as below?
or
You have to make your own custom header row and put that as the first row of each section. Subclassing the UITableView
or the headers that are already there will be a pain. Based on the way they work now, I am not sure you can easily get actions out of them. You could set up a cell to LOOK like a header, and setup the tableView:didSelectRowAtIndexPath
to manually expand or collapse the section it is in.
I'd store an array of booleans corresponding the the "expended" value of each of your sections. Then you could have the tableView:didSelectRowAtIndexPath
on each of your custom header rows toggle this value and then reload that specific section.
Then set numberOfRowsInSection
to check the mybooleans
value and return 1 if the section isn't expanded, or 1+ the number of items in the section if it is expanded.
Also, you will need to update cellForRowAtIndexPath
to return a custom header cell for the first row in any section.
这篇关于iOS UITableView 中的展开/折叠部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!