将UISwitch添加到UITableView的顶部以展开/折叠较低的UITableViewCell(s) [英] Adding a UISwitch to the top of a UITableView to expand/collapse the lower UITableViewCell(s)
问题描述
我是iOS开发的新手,我无法弄清楚如何获得 UISwitch
来展开/折叠 UITableView
现有 UITableViewCell
s(例如,一个 UITableViewCell
,带有 UISwitch 当
和 UISlider
的状态切换为<时,顶部单元格上的code>扩展为5 UITableViewCell
行code> ON OFF
将切换回1行)。我目前有 UITableViewController
类实现了具有分组样式的静态单元格(所以没有 UITableViewDelegate
或 UITableViewDataSource
方法已经实现)。我正在使用最新版本的 iOS(iOS 5.1)。
I am a newbie to iOS development and I am having trouble figuring out how to get a UISwitch
to expand/collapse a UITableView
existing UITableViewCell
s (for example having one UITableViewCell
with the UISwitch
on the top cell expanded to 5 UITableViewCell
rows when the state of the UISlider
is toggled to ON
and OFF
will toggle back to 1 row). I currently have UITableViewController
class implemented has static cells with a grouped style (so no UITableViewDelegate
or UITableViewDataSource
methods have been implemented). I am working with the latest build of iOS (iOS 5.1).
有关如何执行此操作或示例代码的任何说明将非常感谢,谢谢。
Any explanation on how to do this or example code would be much appreciated, Thanks.
推荐答案
我可能错了,但我认为你不能用静态细胞做到这一点。
I could be wrong, but I don't think you can do this with static cells.
以下是我的表现:
- 有一个
BOOL
在表视图控制器中(即,作为委托和数据源的对象)确定单元格2-5是否应该可见 - 当切换UISwitch时,切换
BOOL
,并使用insertRowsAtIndexPaths:withRowAnimation:
或deleteRowsAtIndexPaths:withRowAnimation:
使第2-5行的单元格在适当的时候显示或消失。 - 拥有
numberOfRowsInSection
确定正确的值(1或5),具体取决于单元格2-5是否可见
- Have a
BOOL
in the table view controller (i.e., the object that is the delegate and data source) that determines whether or not cells 2-5 should be visible - When the UISwitch is toggled, toggle the
BOOL
, and useinsertRowsAtIndexPaths:withRowAnimation:
ordeleteRowsAtIndexPaths:withRowAnimation:
to make the cells at rows 2-5 appear or disappear (respectively) as appropriate. - Have
numberOfRowsInSection
determine the right value (1 or 5) depending on whether cells 2-5 should be visible
这篇关于将UISwitch添加到UITableView的顶部以展开/折叠较低的UITableViewCell(s)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!