【发布时间】:2012-08-06 20:40:45
【问题描述】:
我有一个类似的表格视图..
单元格 xxxx、yyyy 和 zzzz 是固定的,因此不会对它们进行点击操作。但是单元格“显示”是可点击的。单击“显示”单元格时,我想在“显示”单元格下显示一些六个单元格。
因此,单击“显示”单元格后,表格将如下所示..
在这里,我所做的是,
将
cell.textLabel.text更改为“显示”为“隐藏”在
tableView:didSelectRowAtIndexPath:方法中使用了[tableView reloadData];。
我的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"My title";
// This Mutable array contains the hided cell objects
hidedCellsArray = [[NSMutableArray alloc] initWithObjects:@"Cell 1", @"Cell 2", @"Cell 3", @"Cell 4", @"Cell 5", @"Cell 6", nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
else if(indexPath.section == 1)
{
if (isShowClicked) //isShowClicked is a boolean value that determines whether the show cell was clicked or not
{
if (indexPath.row == 0)
{
cell.textLabel.text = @"Hide";
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.textAlignment=UITextAlignmentCenter;
}
else
{
cell.textLabel.text = [hidedCellsArray objectAtIndex:indexPath.row-1];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.textAlignment=UITextAlignmentCenter;
}
}
else
{
cell.textLabel.text = @"Show";
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.textAlignment=UITextAlignmentCenter;
}
}
...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1)
{
if (isShowClicked)
{
isShowClicked = NO;
}
else
{
isShowClicked = YES;
}
[tableView reloadData];
}
}
我需要什么:
我想在单击显示/隐藏按钮时为单元格设置动画。我了解到,应该使用
insertRowsAtIndexPaths: withRowAnimation:的方法来实现插入效果。但我真的没有看到任何简单的例子。我是否应该包含任何其他方法,例如setEditing:animated:或tableView: commitEditingStyle: forRowAtIndexPath:方法来执行此操作?第二件事是,在动画(单元格插入)发生之前,我想将 tableview 移动到第 2 节(即“显示”单元格)到顶部。然后应该发生插入单元格的动画。因此,单击显示单元格后表格的最终外观应该是......
需要帮助..我只是困惑!
【问题讨论】:
标签: objective-c uitableview animation scroll insertion