我UITableView
在我的iPhone应用程序中使用了一个,我有一个属于一个组的人员列表.我希望这样当用户点击特定的人(从而选择单元格)时,单元格的高度会增加,以显示多个UI控件来编辑该人的属性.
这可能吗?
我通过setExpanded:方法调用改变高度来扩展单元格.
然后我调用reloadRowsAtIndexPaths:刷新单元格.
问题是细胞消失并随机重新出现.我怀疑这与索引工作方式有关.
如果我调用reloadData或beginUpdates/endUpdates,单元格按预期工作,但我丢失了动画.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
JVCell *cell = (JVCell*)[tableView cellForRowAtIndexPath:indexPath];
JVCell *previousCell = nil;
if( previousIndexPath_ != nil ) // set to nil in viewDidLoad
{
previousCell = (JVCell*)[tableView cellForRowAtIndexPath:previousIndexPath_];
}
// expand or collapse cell if it's the same one as last time
if( previousCell != nil && [previousIndexPath_ compare:indexPath] == NSOrderedSame && [previousCell expandable] )
{
[previousCell setExpanded:![cell expanded]];
NSArray *indexPathArray = [NSArray arrayWithObject:previousIndexPath_];
[tableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
}
else
{
// collapse previous …
Run Code Online (Sandbox Code Playgroud)